爲什麼有些例子的SharePoint使用的SPSite網站=新的SPSite(SPContext.Current.Web.Url)VS SPContext.Current.Web.Site
using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
...
}
,並不能簡單?
SPSite site = SPContext.Current.Web.Site;
...
更新
我想我已經縮小問題到以下幾點:
看來,我不應該直接使用SPContent.Current
,除非我確信,我的代碼中運行SharePoint中。但是,這是不是真的?
看看從我類似的問題:http://sharepoint.stackexchange.com/questions/20192/using-spcontext-current-or-using-static-url –
感謝您的鏈接。我更新了我的問題。 –
在較大的項目中,您有時會遇到不在SharePoint中運行的外部實用程序。另一個例子是單元測試,它也不能在SharePoint中運行。如果您只是開發可視化Web部件而不進行單元測試 - 您的代碼將在SP中運行。 –