November Happy Hour will be moved to Thursday December 5th.

A Question

Vote:
 

Hi 

Is it possible to generate a list of all the files stored in the VPP?

I need all the files in all the directories > even the sub directories that contain sub directories etc not just the first level.

Is this possible in C#?

#205347
Edited, Jul 06, 2019 11:26
Quan Mai - May 04, 2021 9:53
I would suggest to have more "Descriptive" title next time. A question is a bit too generic/vague, don't you agree.
Vote:
 

Soomething like this might give you results you're looking for (you can select whichever property of the media file you need):

List<string> FindAllFiles(ContentFolder contentFolder, IContentRepository repo, List<string> seed)
{
    seed.AddRange(repo.GetChildren<MediaData>(contentFolder.ContentLink).Select(f => f.Name));

    foreach (var f in repo.GetChildren<ContentFolder>(contentFolder.ContentLink))
    {
        FindAllFiles(f, repo, seed);
    }

    return seed;
}

var folder = _repository.Get<ContentFolder>(SiteDefinition.Current.GlobalAssetsRoot);
var allFiles = FindAllFiles(folder, _repository, new List<string>());

`_repository` is just a injected implemention of IContentRepository. Usually you can ask these dependencies via constructor of the class.

#205351
Jul 08, 2019 8:15
Vote:
 

A bit different approach from valdis:

var descendents = _contentRepository.GetDescendents(SiteDefinition.Current.GlobalAssetRoot);

foreach (var descendent in descendents)

{

 var path = _fileBlobProvider.Get(contentLink).BinaryData as FileBlob).FilePath;

//do as you wish with the path

 }

note that if you have a lot of assets, it might be a good idea to use GetChildren with paging instead. 

#254330
May 04, 2021 8:59
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.