Using a Caml query to get a list of all the documents in a list that has folders. The issue I'm having is how to construct the hyperlink. With list that do not have folders I simply append the document name to path to the list to create the hyperlink. However, in this case with folders I need to add the folder name to the list path and don't know how to acquire that information.

How do you get the folder name or is there some way to get the path of the stored document?

1 Answer 1


You could get the folder URL by using ServerRelativeUrl property of Folder object as shown below if you are using CSOM:

using (ClientContext context = new ClientContext("http://localhost"))
                List list = context.Web.Lists.GetByTitle("TestLib0");
                CamlQuery caml = CamlQuery.CreateAllFoldersQuery();
                Folder rootFolder = list.RootFolder;
                FolderCollection folders = rootFolder.Folders;

                foreach (Folder folder in folders)

Reference: https://social.msdn.microsoft.com/Forums/vstudio/en-US/517105fe-d2c3-42c1-a301-623328ac81ee/how-to-get-document-library-folder-url?forum=appsforsharepoint

  • Thanks, I'll check that out. Meantime, while debugging with WDT I noticed fields FileRef and FileLeafRef. FIleRef had the info I needed.
    – PianoMan
    Jan 10, 2018 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.