Question

I have a sandbox solution in SharePoint . I have created number of site columns, Content Types , list definitions and list instances. Everything has individual feature.

For Ex:

  1. Site column feature (Site feature)
  2. Site content type feature (Site feature)
  3. List destination feature (Web feature)
  4. List instance (Web feature)

I have 3 lookup columns which is provisioned successfully without target list.

Lookup column is configured in Content Type and list instance.

Now, I want to update that lookup field using feature receiver and use lookup value in other list.

What should I Do? My lookup Column element.xml is below.

<Field
ID="{a41ab4e5-a30a-4d99-8e0b-1ab2095d68f2}"
Name="Client"
DisplayName="Client"
Type="Lookup"
Required="TRUE"
Group="Test"
List="{00000000-0000-0000-0000-000000000000}"
ShowField="Title">

How can I replace list ID with {00000000-0000-0000-0000-000000000000}?

Was it helpful?

Solution

lstevents = web.Lists["Test"];
fldLookupField = (SPFieldLookup)web.Site.RootWeb.Fields.GetFieldByInternalName("Test");
fldLookupField.SchemaXml = fldLookupField.SchemaXml.Replace("List=\"{00000000-0000-0000-0000-000000000000}\"", string.Format("List=\"{0}\"", lstevents.ID.ToString("B")));
fldLookupField.LookupWebId = lstevents.ParentWeb.ID;
fldLookupField.Update(true);

OTHER TIPS

After a long time, i got the solution of my question . I am sharing with you guys.

lstevents = web.Lists["Test"];
                    fldLookupField = (SPFieldLookup)web.Site.RootWeb.Fields.GetFieldByInternalName("Test");
                    fldLookupField.SchemaXml = fldLookupField.SchemaXml.Replace("List=\"{00000000-0000-0000-0000-000000000000}\"", string.Format("List=\"{0}\"", lstevents.ID.ToString("B")));
                    fldLookupField.LookupWebId = lstevents.ParentWeb.ID;
                    fldLookupField.Update(true);

Add this code to feature activated of List Instances. You can change source id of look up column using this code.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top