Get Documents From All SharePoint Online Documents Libraries

Meet Bhatt 21 Reputation points
2021-02-12T10:09:16.223+00:00

Hello Everyone,

I am using SharePoint online modern team site.

I have created 10+ document libraries in my SharePoint site collection.

I will need get all document librarians documents using PnPJS (Programmatically).

Is anyone can help me for the same?

Thanks in Advance.

Regards,
Meet Bhatt

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,704 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,031 Reputation points
    2021-02-15T03:08:59.31+00:00

    Hi @Meet Bhatt ,

    You could use the bleow to get all documents from all the libraries in the site:

    let getFiles = (folderUrl) => {  
       sp.web.getFolderByServerRelativeUrl(folderUrl)  
            .expand("Folders, Files").get().then(r => {  
                r.Folders.forEach((item) => {  
                if (item.Name !== "Forms") { //ignore Edit/DisplayForm folders  
                  getFiles(item.ServerRelativeUrl);  
                }  
              });  
              r.Files.forEach((item) => {  
                console.log(item.ServerRelativeUrl);  
              });  
            });  
    };  
    sp.site.getDocumentLibraries("https://tenant.sharepoint.com/sites/test").then(function(data){  
          
        for(let d of data){  
          console.log(d.ServerRelativeUrl);  
          getFiles(d.ServerRelativeUrl);  
        }  
    });  
    

    Similar question is here: https://sharepoint.stackexchange.com/questions/289043/get-all-files-in-a-site-collection-with-pnpjs/289051#289051


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.