SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to pull populate a lookup field using a lookup value without the lookup ID. I am getting the error: "One or more field types are not installed properly. Go to the list settings page to delete these fields." I have the following code:

   public static SPFieldLookupValue getLookUpValue(string lookupValue, SPList myList, String LookupField, string LookupSourceField)
       SPFieldLookup lookUpField = (SPFieldLookup)myList.Fields[LookupField];
       SPList lookupSourceList = myList.ParentWeb.Lists.GetList(new Guid(lookUpField.LookupList), false); //ParentWeb.Lists[lookUpField.LookupList];

       SPQuery query = new Microsoft.SharePoint.SPQuery();
       query.Query = String.Format("<Where><Eq><FieldRef Name=’{1}’/><Value Type=’Text’>{0}</Value></Eq></Where>", lookupValue, LookupSourceField);
       SPListItemCollection listItems = lookupSourceList.GetItems(query);
       if (listItems[0] != null)
           return new SPFieldLookupValue(listItems[0].ID.ToString());
       return null;

I call the code like this:

  string LookupValue = null;
  if (properties.ListItem["SupplierID"] != null)
      LookupValue = properties.ListItem["SupplierID"].ToString();
  string FieldFromWhereToLookup = "sup";
  string SourceField = "SupplierID";
  SPFieldLookupValue lookupID = getLookUpValue(LookupValue, properties.List, FieldFromWhereToLookup, SourceField);

While stepping through the code, query.Query shows the following:

        <FieldRef Name=’SupplierID’/>
        <Value Type=’Text’>100367</Value>

I ensured that lookupSourceList is populated with the correct list. U2U CAMLBuilder shows the following when I build a query using the same list, field, and filter value:

        <FieldRef Name="SupplierID" />
        <Value Type="Text">100367</Value>
share|improve this question

Double quotes will do as well, like

 query.Query = String.Format("<Where><Eq><FieldRef Name=\"{1}\"/><Value Type=\"Text\">{0}</Value></Eq></Where>", lookupValue, LookupSourceField);
share|improve this answer
up vote 0 down vote accepted

My single quotes were off.

<Where><Eq><FieldRef Name=’{1}’/><Value Type=’Text’>{0}</Value></Eq></Where>

should have been:

<Where><Eq><FieldRef Name='{1}'/><Value Type='Text'>{0}</Value></Eq></Where>
share|improve this answer

Your Answer


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.