SPSite site = new SPSite(SPContext.Current.Web.Url) vs SPContext.Current.Web.Site

后端 未结 3 1310
旧巷少年郎
旧巷少年郎 2021-02-02 15:17

Why do some SharePoint examples use

using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
    ...
}

and not just simply?



        
3条回答
  •  心在旅途
    2021-02-02 16:21

    It depends on the context in which your code runs. For instance, you need to create a new SPSite instance if you are running within a RunWithElevatedPrivileges block.

提交回复
热议问题