简体   繁体   English

Microsoft Graph .NET SDK - 检索ListItem字段

[英]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. 我正在尝试使用.NET SDK从SharePoint子网站的列表中检索项目。 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". ListItemfields属性是您需要“展开”而不是“选择”的集合。

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: 使用SDK时,您需要以下内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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