What is the best way to get the current site / web listing?
Option 1 - Reusing Existing Objects
SPSite site = SPContext.Current.Site;
SPweb web = SPContext.Current.Web;
SPList list = SPContext.Current.List;
Option 2 - Creating New Objects
SPSite site = new SPSite(SPContext.Current.Site.ID);
SPweb web = site.OpenWeb(SPContext.Current.Web.ID);
SPList list = web.Lists[SPContext.Current.List.ID];
I am having trouble using option 1 in some situations. Since then, I have chosen the second option, and so far it has worked fine.
How do you feel about this? Am I better off going with option 2? Other offers?
source
share