List all files in page folder

Vote:
 

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)
                    {

                    }
                }  
#86402
May 20, 2014 23:43
Vote:
 

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 http://world.episerver.com/Documentation/CMS/ 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))
{
                
}
#86405
May 21, 2014 6:45
Vote:
 

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

#86525
May 23, 2014 4:16
Vote:
 

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

#86578
May 25, 2014 11:49
Vote:
 

Never mind. Found it!

var image = (ImageFile)item;
UrlResolver.Current.GetUrl(image.ContentLink);

#86579
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.