I know that, as a general rule, metadata should be used rather than folders in SharePoint. However, I haven't found anything that discusses the benefits of metadata over folders when it comes to finding files using CSOM.

I have a library that stores files that are associated with a non-SharePoint web form that pertains to customer feedback. I only need to find the existing files for a specific customer, or add new files for that customer.

If I have a library with 5000 files, and I want to find all files where Company = "Some Value", the inspection (either in C# or in SharePoint as it implements CAML filters) must iterate over all 5000 files in the library to find the result set.

If, however, I structure the files so that there is a folder for each company, then I can easily find all files where Company = "Some Value" by setting the FolderServerRelativeUrl and returning all the items the folder contains.

public void DisplaySharepointFiles(string folderUrl = null, int parentFolderId = 0, int level = 0)
    var sourceList = ClientContext.Web.Lists.GetByTitle(DocumentLibrary.Title);

    if (folderUrl != null)
        Query.FolderServerRelativeUrl = folderUrl;
    ListItemCollection items = sourceList.GetItems(Query);

    List<SharepointItem> folderList = new List<SharepointItem>();

    foreach (var item in items)
        var spItem = CreateSharepointItem(item, parentFolderId, level);
        if (spItem.IsFolder)
    //do some unrelated stuff

    //subfolders & files
    foreach (var sItem in folderList)
        DisplaySharepointFiles(sItem.ItemPath, sItem.Id, level + 1);


In light of my use case, are there benefits to avoiding folders and using metadata for locating specific files in a library using CSOM, or are folders less expensive in terms of performance?

1 Answer 1


As a high-level thinking on algorithms, the deeper the tree is, the longer the crawling algorithm is expected to run at least when compared to one-dimensional structure. If you know the "Company" as in your case, sure you can narrow the crawled content, but wouldn't the same apply if it's just a metadata, which can also be fetched with CSOM?

  • I was thinking in terms of objects that must be inspected. I believe (and correct me if I'm wrong), using FolderServerRelativeUrl eliminates the need to inspect any objects. I immediately know that everything below that "node" is what I want to display. If I don't set FolderServerRelativeUrl, all objects must be inspected to determine whether Company metadata = "Some Value". Or is my impression incorrect? Commented Nov 1, 2016 at 15:18
  • 1
    @devlincarnate I see what are after. Unfortunately I can't tell the truth basing it on any citation at least. It seems to come down to the point whether the complexity of getting the folder by its name + returning all results is more effective than crawling a source where the items match a certain metadata. The complexity levels shouldn't be equal, so there's might be a point where one is faster and on another one slower. Probably to find the answer to your case, you'd need to do tests with both setups.
    – moe
    Commented Nov 2, 2016 at 6:26

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.