Reputation: 15660
I have the following working code, that lists all files in a Sharepoint site and also grabs their driveItem details:
var directoryContents = await App.GraphClient.Sites[SiteIdShortName].Lists[sharedDocsDriveId]
.Items
.Request()
.Expand(item => item.DriveItem)
.GetAsync();
SharedDocumentList.ItemsSource = directoryContents.CurrentPage.ToList();
Now I need a way to also grab the publication status for each item, in additional to the data the above query is already getting. I found this post here on stackoverflow:
checkout status of a onedrive file using microsoft graph api
So I've tried to change my code to look like this:
var directoryContents = await App.GraphClient.Sites[SiteIdShortName].Lists[sharedDocsDriveId]
.Items
.Request()
.Expand(item => item.DriveItem)
.Select(item => item.DriveItem.Publication)
.GetAsync();
SharedDocumentList.ItemsSource = directoryContents.CurrentPage.ToList();
But I'm getting the following error message:
Message=Anonymous type in lambda expression may only be initialized with direct members of type ListItem Parameter name: selectExpression Source=Microsoft.Graph
EDIT 1
I also tried this:
var queryOptions = new List<QueryOption>()
{
new QueryOption("select", "publication")
};
var directoryContents = await App.GraphClient.Sites[SiteIdShortName].Lists[sharedDocsDriveId]
.Items
.Request(queryOptions)
.Expand(item => item.DriveItem)
.GetAsync();
SharedDocumentList.ItemsSource = directoryContents.CurrentPage.ToList();
But the error I get is:
Inner Exception 1: JsonReaderException: '{' is invalid after a value. Expected either ',', '}', or ']'. LineNumber: 0 | BytePositionInLine: 223.
Upvotes: 1
Views: 3120
Reputation: 20625
This works for me. In Expand
I've specified the property to be expanded with select
statement which specified property inside the driveItem
var directoryContents = await App.GraphClient.Sites[SiteIdShortName].Lists[sharedDocsDriveId]
.Items
.Request()
.Expand("driveItem($select=publication)")
.GetAsync();
SharedDocumentList.ItemsSource = directoryContents.CurrentPage.ToList();
Upvotes: 1