List.GetItemById - Méthode (Int32)
Returns the list item with the specified list item identifier.
Espace de noms : Microsoft.SharePoint.Client
Assemblys : Microsoft.SharePoint.Client.Silverlight (dans Microsoft.SharePoint.Client.Silverlight.dll); Microsoft.SharePoint.Client.Phone (dans Microsoft.SharePoint.Client.Phone.dll) Microsoft.SharePoint.Client (dans Microsoft.SharePoint.Client.dll)
Syntaxe
'Déclaration
Public Function GetItemById ( _
id As Integer _
) As ListItem
'Utilisation
Dim instance As List
Dim id As Integer
Dim returnValue As ListItem
returnValue = instance.GetItemById(id)
public ListItem GetItemById(
int id
)
Paramètres
id
Type : System.Int32Specifies the list item identifier.
Valeur renvoyée
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. |
Exemples
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"]);
}
}
}