Interview Questions administrator

Best SharePoint administrator Interview Questions and Answers with topic wise:

Recycle Bin | MMS | ManagedVsCrawledProperties |

Saturday, February 25, 2012

Sharepoint LookUp field issue

The below solution will help you while moving the lists which are having the lookups fileds from one site to number sites.
public const string Parent_Child_LookUpFieldName = "LookupFieldName";
public const string CustomParentList = "ParentList";
public const string CustomChildList = "ChildList";

FixLookupFieldsInList(Parent_Child_LookUpFieldName, currentWeb.Lists[CustomParentList], currentWeb.Lists[CustomChildList]);
#region FixLookupFieldsInList
/// FUNCTION        : FixLookupFieldsInList
/// PURPOSE         : To fix the LookupFields in a list imported using a stp file
/// PARAMETERS      : currentWeb -> current web
///                   fieldName -> The column name to be fixed
///                   list -> The list to be fixed
///                   targetList -> Then list to which the fieldName must reference
/// RETURNS         : None
/// ---------------------------------------------------------------------
public static void FixLookupFieldsInList(string fieldName, SPList list, SPList targetList)
   list.ParentWeb.AllowUnsafeUpdates = true;
   if (list.Fields.ContainsField(fieldName))
    SPFieldLookup field = (SPFieldLookup)list.Fields[fieldName];
    //check if the field link to the list is broken. 
    if (field.LookupList != targetList.ID.ToString())
     //copy the schema from the field
     string newFieldXml = field.SchemaXml;
     string oldsourceid = field.LookupList;
     //put the ID of the current list as the source for the lookup
     field.SchemaXml = newFieldXml.Replace(oldsourceid, "{" + targetList.ID.ToString() + "}");
 catch (Exception ex)
  //Error Handling Code
   list.ParentWeb.AllowUnsafeUpdates = false;
Happy coding...

1 comment:

  1. Hi Sasi..Iam new to sharepoint and working on MOSS using webservices -- (SPAPI_Lists), if i add values into sharepoint list that has one look up column using webservices the look up column alloews only 20 records after that it show the saved values as null. why? appriciate you help..