Tuesday, March 18, 2014

In Some situation the content type contains LookUpField which has reference to List Source which is exists in the Site. And suppose that list source is creating from the List Definition by Feature so that time we need to update the List Source GUID to the LookUpField site column and Push that changes . Change the schemaXml of the Field by updating the xml.


using (SPSite site = new SPSite("http://Sitename/"))
       {
       using (SPWeb web = site.OpenWeb())
       {
              SPList list = web.Lists["list"];
              Guid id=list.ID;
              SPFieldLookup look = web.Fields["ListName"] as SPFieldLookup;
              XmlDocument document = new XmlDocument();
              document.LoadXml(look.SchemaXml);
              document.DocumentElement.Attributes["List"].Value = id.ToString();
              look.SchemaXml = document.InnerXml;
              look.LookupField = "Title";
              look.Update(true);
              web.Update();
              }
       }


No comments:

Post a Comment