Hello I am trying to fetch a list item and want to know if this is a good practice.
SPSite spsite = new SPSite(SPContext.Current.Web.Url); SPWeb spWeb = spsite.RootWeb; SPList spList = spWeb.Lists.TryGetList("MyList"); //here is the code to fetch the values...
We have 1 site collection with 50 subsites and more subsites within them. My question is;
Suppose I am on one of the subsites under subsite number 10 and this code is executed, then will it still pickup the root web list or give error?
I am confused because the value of the SPContext.Current.Web.Url will be the current URL at respective location. Then, would the code still work?