I am trying to get a list of items that are contained inside a sharepoint list. When I use the code below I get an error
[ArgumentException: Value does not fall within the expected range.] Microsoft.SharePoint.SPListCollection.GetListByName(String strListName, Boolean bThrowException) ...
The structure is MainSite>Subweb>Subweb>Subweb>List
Am I calling this wrong since it is inside of 3 subwebs?
using (SPSite site = new SPSite(SPContext.Current.Site.Url.ToString()))
using (SPWeb oWebsiteRoot = site.OpenWeb())
{
SPList oList = oWebsiteRoot.Lists["SInfo"];
SPListItemCollection items = oList.Items;
foreach (SPListItem listitem in items)
{
Response.Write(SPEncode.HtmlEncode(listitem["SName"].ToString()) + "<BR>");
}
}