List all files in page folder


I've got a piece of code from out 6.5 project that is not working in 7.5. Any idea why?

VirtualPathUnifiedProvider provider = (VirtualPathUnifiedProvider)VirtualPathHandler.GetProvider("SitePageFiles");
                int id = (int)(CurrentPage["PageFolderID"] ?? 0);
                string pageFolderName = VirtualPathUtility.AppendTrailingSlash(id.ToString()) ?? string.Empty;
                string path = VirtualPathUtilityEx.Combine(provider.VirtualPathRoot, pageFolderName) ?? string.Empty;

                if (provider.DirectoryExists(path))
                    UnifiedDirectory vdir = (UnifiedDirectory)provider.GetDirectory(path);

                    foreach (UnifiedFile file in vdir.Files)

May 20, 2014 23:43

First of all, are you using the new file system? The old one was based on VPP and the new is ContentData, just as pages and blocks. Please have a look in the SDK under the Assets and media heading.

This would be the equivalent to your code in 7.5:

var helper = ServiceLocator.Current.GetInstance<ContentAssetHelper>();
var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();

var folder = helper.GetOrCreateAssetFolder(CurrentPage.ContentLink);

foreach (var item in contentLoader.GetChildren<MediaData>(folder.ContentLink))
May 21, 2014 6:45

Excuse my late reply. Thanks for you code snippet, Johan. Worked like a charm!

May 23, 2014 4:16

How do I get the URL of the item so that I can render the items in the markup?

May 25, 2014 11:49

Never mind. Found it!

var image = (ImageFile)item;

May 25, 2014 11:57
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.