0

I'm creating a function to log all changes in a SharePoint list.

In fact I have a simple question: How to set a lookup field = NULL?

  • How are you tracking the changes? What all you have tried so far? – Amal Hashim Nov 12 '14 at 15:00
  • Hello Amal, Item[field] = new SPFieldLookupValue("") – JulianoG Nov 12 '14 at 15:01
  • What error you are getting? – Amal Hashim Nov 12 '14 at 15:03
  • Value cannot be null. Parameter name: source – JulianoG Nov 12 '14 at 15:04
  • Is it a required field? – Amal Hashim Nov 12 '14 at 15:07
1

Below code worked for me

        using (SPSite site = new SPSite("http://siteurl"))
        {
            using (SPWeb web = site.OpenWeb())
            {
                SPList list = web.Lists.TryGetList("test");
                if (list != null)
                {
                    SPListItem li = list.AddItem();
                    li["Title"] = "Test NULL 2";
                    li["StartDate"] = DateTime.Now;
                    li["EndDate"] = DateTime.Now;
                    li["lookupcolumn"] = null;

                    li.Update();
                }
            }
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.