Lookup fields one site to number of sites
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() + "}");
}
}
list.ParentWeb.AllowUnsafeUpdates = false;
No comments:
Post a Comment