I am using a document library. It could have folders and files in it. My requirement is to fetch all content from the document library using an API (https://some.domain.com/folder/{id})
My current logic is using STACK
At root folder -
public async Task<Content> RetrieveDocuments(string url, string id)
{
var files = new List<string>();
var stack = new Stack<string>();
stack.Push(id);
while (stack.Count > 0)
{
var roundId = stack.Pop();
var response = Make An API call (https://some.domain.com/folder/{id})
if (response != null)
{
response.Folders?.ForEach(f => stack.Push(f.FolderId));
response.Files?.ForEach(f => files.Add(resourceRegex.Replace(f.Path, "/")));
}
}
return files;
}
Now the problem here is - if the there are a lot of files in recursively placed folders.. it becomes very time consuming and this function call often leads to timeout.
can anyone suggest a better way of doing it.