다음을 통해 공유


List.GetItemById Method (Int32)

Returns the list item with the specified list item identifier.

Namespace:  Microsoft.SharePoint.Client
Assemblies:   Microsoft.SharePoint.Client.Silverlight (in Microsoft.SharePoint.Client.Silverlight.dll);  Microsoft.SharePoint.Client (in Microsoft.SharePoint.Client.dll)

Syntax

'Declaration
<RemoteAttribute> _
Public Function GetItemById ( _
    id As Integer _
) As ListItem
'Usage
Dim instance As List
Dim id As Integer
Dim returnValue As ListItem

returnValue = instance.GetItemById(id)
[RemoteAttribute]
public ListItem GetItemById(
    int id
)

Parameters

Return Value

Type: Microsoft.SharePoint.Client.ListItem
Returns a ListItem representing the list item with the specified list item identifier.

Exceptions

Exception Condition
[System.ArgumentException]

List item does not exist. Error code: -2147024809.

[System.UnauthorizedAccessException]

The current user has insufficient permissions. Error code: -2147024891.

Examples

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"]);
        }
    }
}

See Also

Reference

List Class

List Members

GetItemById Overload

Microsoft.SharePoint.Client Namespace