we have a user control on the master page (this masterpage is applied to all sites in the web application).
User control code:
SPSite spsite = new SPSite(SPContext.Current.Web.Url);
SPWeb spWeb = spsite.RootWeb;
SPList spList = spWeb.Lists.TryGetList("MyMenu");
if (spList != null)
{
SPQuery qry = new SPQuery();
qry.Query =
@" <OrderBy>
<FieldRef Name='Title' />
</OrderBy>";
qry.ViewFields = @"<FieldRef Name='Title' /><FieldRef Name='URL' />";
SPListItemCollection listItems = spList.GetItems(qry);
}
The MyMenu list is present in the ROOT site collection's (the 1st site collection which we create after creating webapplication) ROOT site.
How do I write code that will allow me to access this list from any place in the web application? At present if we open a other site collection (attach debugger to the w3p) then the list is returned as null.