Get Folders content using Graph SDK – C#

Actually I’m using Microsoft Graph SDK for get my SharePoint content and upload files.

var driveItems = await _graph.Sites["myCompany.sharepoint.com"]
                             .Drive
                             .Root
                             .Children
                             .Request()
                             .GetAsync();

But using this code snippet, I’m stuck on root folder. Which means I can’t get the files located on a folder, or upload a file in his subfolder, for example.

How can I navigate between folders using this Microsoft Graph SDK?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Yes, you can get the list of files and folders by using the code which you shared and I have tested it as below.

Used the Code :-

var driveItems = await graphClient.Sites["soaadteam.sharepoint.com,c1178396-d845-46fa-bc0c-453d2951dad5,19ee9a1e-001d-48f1-9ee8-b0adfde54e45"]
                             .Drive
                             .Root
                             .Children
                             .Request()
                             .GetAsync();

                foreach(var items in driveItems)
                {
                    Console.WriteLine(items.Name);
                }

Result:-
A folder and a file.

Get Folders content using Graph SDK - C#

The only reason that you are not getting those files could be due to the permissions that you don’t have in your scope. Please add Sites.Read.All permission and try to read the results.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x