Home > Enterprise >  How to get file names from a SharePoint folder
How to get file names from a SharePoint folder

Time:06-03

I am trying to get the name of all the files in a folder but I don't know how to do it. This is my code

var items = await client
             .Sites["xxxx.sharepoint.com,xxxx-xxx-xxxx....,xxxx-xxx-xxxx...."]
             .Drives[":/drives/Documentos"]
             .Request()
             .GetAsync();

CodePudding user response:

Per my test, when I try https://graph.microsoft.com/v1.0/drives/drive_id/root/children, I can get all the items in the root folder. Since I don't have a sharepoint site, so I can't test with a sharepoint site, but it should be similar. If you don't want to get all the elements in root folder, you can then follow this section to get specific item children items with /drives/{drive-id}/items/{item-id}/children.

var files = await client.Sites["xxxx.sharepoint.com,xxxx-xxx-xxxx....,xxxx-xxx-xxxx...."]
                   .Drives[":/drives/Documentos"].Root.Children.Request().GetAsync(); 
foreach(var file in files)
{
      var fileName = file.Name;
}
  • Related