Sharepoint在线办公365列出由asp.net表单提交按钮创建的项目

问题描述 投票:0回答:1

我对Office 365上托管的SharePoint Online有疑问。

  1. 我有一个包含三个字段和一个Submit按钮的ASP.NET表单。这些领域是:Namelastnamedisplay name
  2. 我在SharePoint Online网站上有一个自定义列表,其中包含相同的字段:Namelastnamedisplay name

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

我怎样才能做到这一点?

asp.net sharepoint office365 sharepoint-online
1个回答
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();  
© www.soinside.com 2019 - 2024. All rights reserved.