I'm trying to access list items from an other site collection than the current "sitecollectionname" where I laungh my code in. I would like to validate the url of the current "sitecollectionname" with one of the fields/columns named 'Site Url' of the items in the 'Mylist'.
http://myserver/ root site
http://myserver/managedpathA/ root site with MyList
http://myserver/managedpathB/sitecollectionname
VS2010 indicates a problem with the listUrl passed in GetList...
When putting the MyList in the root site at http://myserver/ and using SPSite("http://myserver") it works fine...
using (SPSite site = new SPSite("http://myserver/managedpathA"))
{
using (SPWeb web = site.RootWeb)
{
SPWeb cweb = SPContext.Current.Web;
string siteurl = cweb.Url.ToString();
// Get data from a list.
string listUrl = "/Lists/MyList";
SPList list = web.GetList(listUrl);
SPListItemCollection items = list.Items;
for(int i=0; i<items.Count;i++)
{
SPListItem listItem = items[i];
string listsiteurl = listItem["Site Url"].ToString();
if (siteurl == listsiteurl)
{
OutputLabel.Text = listItem["Site Url"].ToString() + "Found in List"+ "<br/>";
}
else
{
OutputLabel.Text = "No match found for current ste url in MyList";
}
}
}
}