question

ArmDezii-7977 avatar image
0 Votes"
ArmDezii-7977 asked ArmDezii-7977 commented

How to list Files in Shared Documents

How can I programmatically list Files in a Folder under Shared Documents on a SharePoint Site? I have listed the URL below and I am looking to retrieve a listing of all *.jpgs in the Photo Folder. This would be analogous to recursively using the Dir() Function in VBA to achieve this end, however, this approach will not work in this context. Thanks in advance for any suggestions

 https://organization.sharepoint.com/sites/FOHTeam2/Shared%20Documents/Photos/*.jpg


office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RaytheonXie-MSFT avatar image
0 Votes"
RaytheonXie-MSFT answered ArmDezii-7977 commented

Hi @ArmDezii-7977 ,
Our forum mainly focus on C# code. I can provide you with a C# solution. As a workaround, you can try to use some tools to convert C# code to vba.

 ClientContext cxt = new ClientContext("http://xxx/sites/test");
 List list = cxt.Web.Lists.GetByTitle("Documents");
    
 cxt.Load(list);
 cxt.Load(list.RootFolder);
 cxt.Load(list.RootFolder.Folders);
 cxt.Load(list.RootFolder.Files);
 cxt.ExecuteQuery();
 FolderCollection fcol = list.RootFolder.Folders;
 List<string> lstFile = new List<string>();
 foreach(Folder f in fcol)
 {
     if (f.Name.EndsWith(".jpg"))
     {
         cxt.Load(f.Files);
         cxt.ExecuteQuery();
         FileCollection fileCol = f.Files;
         foreach (File file in fileCol)
         {
             lstFile.Add(file.Name);
         }
     }
 }

Since your issue is about sharepoint development with vba. You can also get some more professional answer in techcommunity



If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for your answer, I actually have friends who program in C+, I'll consult with them.

0 Votes 0 ·
sadomovalex avatar image
0 Votes"
sadomovalex answered ArmDezii-7977 commented

the following methods may be used both for Sharepoint on-prem and online:

JSOM solution: How to retrieve files inside folder using javascript
CSOM solution: How to get all the files inside the folder in list
PowerShell solution: Get All Files from a Folder using PowerShell

The following method will work only in on-prem:
Server OM: How to read items from folder in SharePoint List/Library Programmatically C#


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you, sadomovalex, for your response. I am looking for a purely VBA based solution, is this possible?

0 Votes 0 ·