简体   繁体   中英

Microsoft Graph .NET SDK - Retrieving ListItem Field

I'm trying to retrieve the items from a list in a SharePoint subsite with the .NET SDK. I can get the subsite, list, and items, but I don't know how to retrieve the columns. For example, here I'm trying to list all the titles of each list item:

IListItemsCollectionPage items = await graphClient
    .Sites[targetstate_id]
    .Lists[targetlist_id]
    .Items
    .Request()
    .Select("Fields")
    .GetAsync();

Console.WriteLine("Chosen ID: " + lists[listindex].Id);
Console.WriteLine("Number of items: " + items.Count);
for (var index = 0; index < items.Count; index++) {
    //(attempting) at writing the title of each item in list
    Console.WriteLine("Title " + items[index].Fields.AdditionalData["Title"]);
}
Console.WriteLine("Completed");

What's the issue here?

The fields property of a ListItem is a collection that you need to "expand" rather than "select".

The code you're using here is executing the following query:

https://graph.microsoft.com/v1.0/sites/{id}/lists/{id}/items?$select=fields

What you want however is:

https://graph.microsoft.com/v1.0/sites/{id}/lists/{id}/items?$expand=fields

When using the SDK, you'll want something like this:

IListItemsCollectionPage items = await graphClient
    .Sites[targetstate_id]
    .Lists[targetlist_id]
    .Items
    .Request()
    .Expand("fields")
    .GetAsync();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM