Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

So SPFieldLookup has an actual Guid for LookupWebId property and only a string for the LookupList property. So the line

SPList lookupList = lookupWeb.Lists[lookupField.LookupList];

Is using the string override which looks up the list name.

So the learning here, yet again, is do not expect the SharePoint object model to be consistent in any way.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.