문제

Don't web.Dispose() dispose parent SPSite object?

Is it Ok if I do this in web part?

{              
    SPSite site = SPContext.Current.Site;

    using (SPWeb web = site.OpenWeb(s))
    {
         // ..
    }
}
도움이 되었습니까?

해결책

The code you written is Ok.

using statement will dispose the SPWeb object you have instantiated.

Parent Site - This object is not initiantiated by you, you are using SPSite that belongs to SPContext.

SPContext objects are managed by the SharePoint framework and should not be explicitly disposed in your code. This is true also for the SPSite and SPWeb objects returned by SPContext.Site, SPContext.Current.Site, SPContext.Web, and SPContext.Current.Web.

다른 팁

Yes, it's acceptable to do what you have done. It's also ok to pass that web object to other functions.

See a detailed article on this subject from Microsoft here.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top