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);
ClientContext.Load(items);
ClientContext.ExecuteQuery();
List<SharepointItem> folderList = new List<SharepointItem>();
foreach (var item in items)
{
var spItem = CreateSharepointItem(item, parentFolderId, level);
if (spItem.IsFolder)
{
folderList.Add(spItem);
}
}
//do some unrelated stuff
//subfolders & files
foreach (var sItem in folderList)
{
DisplaySharepointFiles(sItem.ItemPath, sItem.Id, level + 1);
}
}
Question
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?