亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

SharePoint 更新列表項

SharePoint 更新列表項

C#
江戶川亂折騰 2023-05-13 16:13:11
我正在嘗試更新 SharePoint 列表,我在 Internet 上找到了一個代碼示例(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 不包含 Items 的定義,并且找不到可訪問的擴展方法“接受類型為‘List’的第一個參數”知道我必須做什么才能使用此代碼嗎?
查看完整描述

1 回答

?
嚕嚕噠

TA貢獻1784條經驗 獲得超7個贊

您提供的用于更新列表項的代碼適用于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();


查看完整回答
反對 回復 2023-05-13
  • 1 回答
  • 0 關注
  • 181 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號