Notice: Undefined index: in /data/phpspider/phplib/misc.function.php on line 226

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SharePoint更新列表项_C#_Sharepoint - Fatal编程技术网

C# SharePoint更新列表项

C# SharePoint更新列表项,c#,sharepoint,C#,Sharepoint,我正在尝试更新SharePoint列表,我在Internet上找到了一个代码示例(officail Microsoft文档) 这就是代码: using System; using Microsoft.SharePoint.Client; using SP = Microsoft.SharePoint.Client; namespace Microsoft.SDK.SharePointServices.Samples { class UpdateListItem {

我正在尝试更新SharePoint列表,我在Internet上找到了一个代码示例(officail Microsoft文档) 这就是代码:

using System;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointServices.Samples
{
    class UpdateListItem
    {
        static void Main()
        {   
            string siteUrl = "http://MyServer/sites/MySiteCollection";

            ClientContext clientContext = new ClientContext(siteUrl);
            SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");
            ListItem oListItem = oList.Items.GetById(3);

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

            oListItem.Update();

            clientContext.ExecuteQuery(); 
        }
    }
}
如果我在visual studio中复制/跳过此代码, 我在这行有一个错误:

ListItem oListItem = oList.Items.GetById(3);
列表不包含项的定义,并且找不到接受类型为“List”的第一个参数的可访问扩展方法

你知道我要怎么做才能使用这个代码吗


谢谢

您提供的用于更新列表项的代码适用于
SharePoint 2010
。对于较新的版本,请尝试

ListItem oListItem=oList.GetItemById(3)

// Starting with ClientContext, the constructor requires a URL to the 
// server running SharePoint. 
ClientContext context = new ClientContext("http://SiteUrl"); 

// Assume that the web has a list named "Announcements". 
List announcementsList = context.Web.Lists.GetByTitle("Announcements"); 

// Assume there is a list item with ID=1. 
ListItem listItem = announcementsList.GetItemById(1); 

// Write a new value to the Body field of the Announcement item.
listItem["Body"] = "This is my new value!!"; 
listItem.Update(); 

context.ExecuteQuery();

您提供的用于更新列表项的代码适用于
SharePoint 2010
。对于较新的版本,请尝试

ListItem oListItem=oList.GetItemById(3)

// Starting with ClientContext, the constructor requires a URL to the 
// server running SharePoint. 
ClientContext context = new ClientContext("http://SiteUrl"); 

// Assume that the web has a list named "Announcements". 
List announcementsList = context.Web.Lists.GetByTitle("Announcements"); 

// Assume there is a list item with ID=1. 
ListItem listItem = announcementsList.GetItemById(1); 

// Write a new value to the Body field of the Announcement item.
listItem["Body"] = "This is my new value!!"; 
listItem.Update(); 

context.ExecuteQuery();