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;
UnifiedDirectory vdir = (UnifiedDirectory)provider.GetDirectory(path);
foreach (UnifiedFile file in vdir.Files)
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))
Excuse my late reply. Thanks for you code snippet, Johan. Worked like a charm!
How do I get the URL of the item so that I can render the items in the markup?
Never mind. Found it!
var image = (ImageFile)item;UrlResolver.Current.GetUrl(image.ContentLink);