I am trying to load a drop down list with the same items that a lookup field uses. I thought it would be relatively straightforward, but the line
SPList lookupList = lookupWeb.Lists[lookupField.LookupList];
Throws an exception despite the list with that ID existing in the SPWeb. (I checked both through the object model and SharePoint Manager)
SPFieldLookup lookupField = targetLibrary.Fields["DocumentType"] as SPFieldLookup;
using (SPWeb lookupWeb = SPContext.Current.Site.OpenWeb(lookupField.LookupWebId))
{
SPList lookupList = lookupWeb.Lists[lookupField.LookupList];
foreach (SPListItem item in lookupList.Items)
{
ddlDocumentType.Items.Add(new ListItem(item["Title"].ToString(), item["ID"].ToString()));
}
}
List '{843fa16d-ec85-45c3-8d27-20d0241d41d6}' does not exist at site with URL
Is there something simple I am missing?