List.GetItemById 方法 (Int32)
Returns the list item with the specified list item identifier.
命名空间: Microsoft.SharePoint.Client
程序集: Microsoft.SharePoint.Client.Silverlight(位于 Microsoft.SharePoint.Client.Silverlight.dll 中); Microsoft.SharePoint.Client.Phone(位于 Microsoft.SharePoint.Client.Phone.dll 中) Microsoft.SharePoint.Client(位于 Microsoft.SharePoint.Client.dll 中)
语法
声明
Public Function GetItemById ( _
id As Integer _
) As ListItem
用法
Dim instance As List
Dim id As Integer
Dim returnValue As ListItem
returnValue = instance.GetItemById(id)
public ListItem GetItemById(
int id
)
参数
id
类型:System.Int32Specifies the list item identifier.
返回值
类型:Microsoft.SharePoint.Client.ListItem
Returns a ListItem representing the list item with the specified list item identifier.
异常
异常 | 条件 |
---|---|
[System.ArgumentException] | List item does not exist. Error code: -2147024809. |
[System.UnauthorizedAccessException] | The current user has insufficient permissions. Error code: -2147024891. |
示例
This code example gets a list item with a specified identifier.
using System;
using Microsoft.SharePoint.Client;
namespace Microsoft.SDK.SharePointFoundation.Samples
{
class List_getItemByIdExample
{
static void Main()
{
string siteUrl = "http://MyServer/sites/MySiteCollection";
ClientContext clientContext = new ClientContext(siteUrl);
Web site = clientContext.Web;
List targetList = site.Lists.GetByTitle("Announcements");
// Get the list item from the Announcements list whose Id is 4.
// Note that this is the ID of the item in the list, not a reference to its position.
ListItem targetListItem = targetList.GetItemById(4);
// Load only the title.
clientContext.Load(targetListItem,
item => item["Title"]);
clientContext.ExecuteQuery();
Console.WriteLine("Request succeeded. \n\n");
Console.WriteLine("Retrieved item is: {0}", targetListItem["Title"]);
}
}
}