Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

List asset folder content

Vote:
 

Hello

For a certain page, say the start page, i have N number of asset folders (Folder1, Folder2, Folder3 etc). Stored in these are documents related to each folder.

I need to list the documents per folder. How do I get handles or such for each folder, and then read it's contents? I've been messing around with ContentAssetHelper and GetAssetFolder() (ie I googled it without finding any good examples) but with absolutely no luck at all.

Any help greatly appreciated.

Kind regards,

Patrik

#84663
Apr 04, 2014 8:18
Vote:
 

Hi, this code may be helpfull it lists all images for a page. It shold be fairly easy to list folders instead.

 

   public static IEnumerable<ImageFile> GetPageImages(PageData page)

        {

            IEnumerable<ImageFile> images = null;

         

                if (page != null  && page.ContentAssetsID != Guid.Empty)

                {

                    var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();

                    var contentAssetFolder = contentRepository.Get<ContentAssetFolder>(page.ContentAssetsID);

                    images = contentRepository.GetChildren<ImageFile>(contentAssetFolder.ContentLink);

                }

              

            return images;

        }

#84664
Apr 04, 2014 8:54
Vote:
 

Thanks for your reply Daniel. Question: I'm trying to read the folders by replacing <ImageFile> (which I had working earlier) with <ContentAssetFolder> but that gives an empty result. It should, in my case, return a list or IEnumerable containing 4 folders.

Code:

IEnumerable<ContentAssetFolder> folders = repo.GetChildren<ContentAssetFolder>(contentAssetFolder.ContentLink);

Any ideas?

Regards,

Patrik

#84712
Edited, Apr 04, 2014 20:14
Vote:
 

Instead of ContentAssetFolder, what is returned when you do IContent instead?

#84713
Apr 04, 2014 20:37
Vote:
 

Try debugging with this IEnumerable<IContent> folders = repo.GetChildren<IContent>(contentAssetFolder.ContentLink);

Just to see if you have the folders in some "dynamic array structure way", then try to extract the folders and casting them if necessary.

/Daniel

 

#84736
Apr 07, 2014 9:04
Vote:
 

Hello Joshua and Daniel,

enumerating IContent works perfect. The exact cast is <ContentFolder>.

Thanks!

#84748
Apr 07, 2014 12:00
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.