0
votes

I have a question regarding SharePoint Online hosted on Office 365.

  1. I have an ASP.NET form with three fields and a Submit button. The fields are: Name, lastname, and display name.
  2. I have a custom list on a SharePoint Online site with the same fields: Name, lastname, and display name.

I want to save the data to the SharePoint list when a user fills the form and clicks the submit button.

How can I do that?

1

1 Answers

1
votes

You can update a list item on SharePoint Online using the Client Side Object Model:

using(ClientContext clientContext = new ClientContext(siteUrl))
{
 clientContext.Credentials = new SharePointOnlineCredentials(userName,password);
                SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");
                ListItem oListItem = oList.Items.GetById(3);

                oListItem["Title"] = "My Updated Title.";

                oListItem.Update();

                clientContext.ExecuteQuery(); 
}

For creating a new item, use the following code:

List announcementsList = context.Web.Lists.GetByTitle("Announcements"); 

// We are just creating a regular list item, so we don't need to 
// set any properties. If we wanted to create a new folder, for 
// example, we would have to set properties such as 
// UnderlyingObjectType to FileSystemObjectType.Folder. 
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); 
ListItem newItem = announcementsList.Items.Add(itemCreateInfo); 
newItem["Title"] = "My New Item!"; 
newItem["Body"] = "Hello World!"; 
newItem.Update();