Search code examples
c#excelmicrosoft-graph-apisharepoint-onlinemicrosoft-graph-sdks

Using MS Graph to Read Excel Contents Through Sharepoint


I'm attempting to use MS Graph to parse the contents of excel files and sync the data with other business-line applications. The issue I'm running into is actually getting at the data in excel.

I'm using a ClientCredentialProvider authenticating to an Azure AD App Registration which has FullControl and Read.All permissions in my tenant to create my GraphServiceClient, and can successfully query the Site via ID, and even see the document library I'm trying to access, but the Items comes up empty. See below

var result = _graphService.Client
                .Sites["my-site-id"] // This works                
                .Drives["site-drive-id"] // This works to find the document library
                //.Lists["list-id-corresponding-to-folder"] // This also works to find that folder
                .Items // ****This is null****
                .Request()
                .GetAsync()
                .Result;

I tried using the Lists property (as noted above) because as I understand it document libraries in SharePoint are really just lists, but again the Items enumeration yields no results.

I can't find documentation on Microsoft's site on this use case, and I notice using the MS Graph Explorer that the returned object doesn't have an "items" field (or many properties in the Microsoft.Graph.Site class), but I would think there is some way to get this field populated since it's implemented in the Microsoft.Graph namespace. Not sure if I'm missing some permissions step or what, but if I can access the site with FullControl I should be able to access all its contents...

I can't use Client.Me (personal drive) as a source location because 1) the application doesn't run under my permissions and 2) there is a need to read multiple files; the idea would be just provide the needed site/drive/item ID's and get the documents.

Is there some other way I should be going about this?


Solution

  • @broccoli_rob,

    MS Graph has not exposed the functionality of enumerating all items in a drive. Instead, you can only list children or get item by id.

    We suggest you use /drive/root:/{item-path} to get items in a folder. And you can vaild the endpoint in Graph explorer:

    enter image description here

    BR