Thursday, January 26, 2017

Creating a list item in Sharepoint List from c#




    <add key="SharePointSIte" value="https://abc.com/sites/ISS/ts/buslead/"/>
    <add key="apiList" value="Business Lead QA list"/>


using Microsoft.SharePoint.Client;

ClientContext clientContext = new ClientContext(siteUrl);
                    SP.List oList = clientContext.Web.Lists.GetByTitle(apiList);

                    ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                    ListItem oListItem = oList.AddItem(itemCreateInfo);
                    oListItem["Title"] = lead.LeadName;
                    oListItem["City"] = lead.City;
                    oListItem["Zip_x0020_Code"] = lead.Zip;
                    oListItem["Address_x0020_1"] = lead.Address1;
                   // oListItem["Address_x0020_2"] = lead.Address2;
                    oListItem["Phone_x0020_number"] = lead.UserPhone;
                    oListItem["Email_x0020_Address"] = lead.UserEmail;
                    oListItem["Branch_x0020_Code"] = lead.BranchCode;
                    oListItem["Branch_x0020_Name"] = lead.BranchName;
                    oListItem["FullName"] = lead.UserFullName;
                    oListItem["Notes"] = lead.Remark;
                    oListItem["Business_x0020_contact_x0020_nam"] = lead.LeadContactName;
                    oListItem["Business_x0020_contact_x0020_add"] = lead.LeadContactPhone;
                    oListItem["Business_x0020_contact_x0020_cit"] = lead.LeadContactEmail;
                    oListItem["Business_x0020_contact_x0020_sta"] = lead.LeadAcquisition;

                    oListItem.Update();

                    clientContext.ExecuteQuery();


No comments: