I have a SharePoint site. I am trying to open a subsite and get a list of all lists in that subsite. This code returns the top level “http://myspserver” lists.
How do I get only the lists from /mysubsite?
string webUrl = "http://myspserver/mysubsite";
using (SPWeb oWebsite = new SPSite(webUrl).OpenWeb()) //Open SP Web
{
SPListCollection collList = oWebsite.Lists; //Open Lists
foreach (SPList oList in SPContext.Current.Web.Lists)
//For Each List Execute this
{
....
}
}
You should iterate over
collList, notSPContext.Current.Web.Lists.SPContext.Current.Web.Listswill get the site you are currently in. Presumably, this ishttp://myspserverwhen you run your code.Also, note that your code leaks – you do not dispose of the SPSite object. It should look like: