Sharepoint 列表项目值与图表 API

Sharepoint List Items values with Graph API

我有一个 SharePoint 列表,我可以通过 Graph API 成功连接到它。它拉出列表项,但似乎只显示基本数据。如何获取字段和这些字段中包含的数据,以便我可以显示/更新该数据?

此外,我假设 SPO 图 API 点是:https://graph.microsoft.com/v1.0/

var assetlist = await graphClient
            .Sites[AllCompanySiteID]
            .Lists[CurrentBuildsListID]
            .Items
            .Request()
            .GetAsync();

        totalitems.AddRange(assetlist.CurrentPage);

        while (assetlist.NextPageRequest != null)
        {
            assetlist = assetlist.NextPageRequest.GetAsync().Result;
            totalitems.AddRange(assetlist.CurrentPage);
        }

不清楚您是想 (1) 仅获取数据字段仅更新​​数据字段 还是 (2) 您需要从选择中更新数据字段 - 如有疑问,我会写这两种方法。如果您的需求是第 (2) 项,您可能希望 map/model 业务规则来开发例程。根据 Microsoft Docs,以下示例:

(1) 仅获取数据字段:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var queryOptions = new List<QueryOption>()
{
    new QueryOption("expand", "fields(select=Field1,Field2,Field3)")
};

var items = await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items
    .Request( queryOptions )
    .GetAsync();

(1) 仅更新​​数据字段:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var fieldValueSet = new FieldValueSet
{
    AdditionalData = new Dictionary<string, object>()
    {
        {"Field1", "Test1"},
        {"Field2", "Test2"}
    }
};

await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items["{listItem-id}"].Fields
    .Request()
    .UpdateAsync(fieldValueSet);

(2) 根据选择更新数据字段 示例:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );
    
    var queryOptions = new List<QueryOption>()
    {
        new QueryOption("expand", "fields(select=Field1,Field2,Field3)")
    };
    
    var items = await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items
        .Request( queryOptions )
        .GetAsync();
foreach(var item in items)
{
    //an example of Business Rule: Update item based by some Select into current item
    if(null != item.Fields.AdditionalData["Field1"] && !string.IsNullOrWhiteSpace(item.Fields.AdditionalData["Field1"].ToString()))
    {
        var fieldValueSet = new FieldValueSet
        {
            AdditionalData = new Dictionary<string, object>()
            {
                {"Field2", "Test2"},
                {"Field3", "Test3"}
            }
        };
        await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items[item.Id.ToString()].Fields
        .Request()
        .UpdateAsync(fieldValueSet);
    }
}