List.GetItemById 方法 (Int32)
傳回具有指定清單項目識別碼的清單項目。
命名空間: 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.Int32指定清單項目識別碼。
傳回值
類型:Microsoft.SharePoint.Client.ListItem
傳回代表指定的清單項目識別碼清單項目ListItem 。
例外狀況
例外狀況 | 條件 |
---|---|
[System.ArgumentException] | 清單項目不存在。錯誤碼 ︰-2147024809。 |
[System.UnauthorizedAccessException] | 目前的使用者會有足夠的權限。錯誤碼 ︰-2147024891。 |
範例
此範例中的程式碼會指定識別項的清單項目。
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"]);
}
}
}