Thursday, 13 March 2014

insert lookup field in sharepoint custom list using c#

Share it Please
 SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList list = web.Lists[ListName];
                        SPListItem newitem = list.Items.Add();
                        newitem["Title"] = "New lookup";
                        SPFieldLookupValue newValue = new SPFieldLookupValue(1, "Title1");
                        newitem["Title1"] = newValue;
                        newitem.Update();
                    }
                }
            });

No comments:

Post a Comment

Followers

Follow The Author