2014-05-15 28 views
-2

我有一个关于SharePoint Online中托管的Office 365SharePoint Online中Office 365的列表项提交按钮

  1. 我有三个字段和一个提交按钮的ASP.NET表单中的问题。这些字段是:Name,lastnamedisplay name
  2. 我有一个SharePoint Online站点上的相同字段的自定义列表:Name,lastnamedisplay name

我想在用户填写表单并单击提交按钮时将数据保存到SharePoint列表。

我该怎么做?

回答

1

可以使用客户端对象模型更新SharePoint Online的一个列表项:

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(); 
} 

为了创建一个新的项目,使用下面的代码:

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(); 
相关问题