Posts

Showing posts with the label lookup fields

Sharepoint Updating / Changing Lookup Fields from code

unfortunately the only way to do it correctly is to change the SchemaXml itself for most changes like ListID or ColumnID ect. here is a Sample: public static void FixLookup ( SPFieldLookup lookupField , Guid newListGuid ) {     Log . Application . Info ( "FixLookup" );     if ( lookupField . LookupList != newListGuid . ToString ())    {       Log . Application . Info ( "update schema" );       int startIndexOfList = lookupField . SchemaXml . IndexOf ( "List" );       int startIndex = lookupField . SchemaXml . IndexOf ( "\"" , startIndexOfList ) + 1 ;       int endIndex = lookupField . SchemaXml . IndexOf ( "\"" , startIndex );       int countIndex = endIndex - startIndex ;       string oldGuid = lookupField . SchemaXml . Substring ( startIndex , countIndex );       lookupField . SchemaXml = lookupFiel...