AI OnAI Off
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.
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.
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#?