As stated in the end of the article, page files are different and you can get the PageFolderID (which is part of the path) from the corresponding PageData object.
Yeah, what I don't get about that is how to use it in the code. What part should I change?
Something like this: Get the folder ID and append it to the directory path:
var id = (int)(CurrentPage["PageFolderID"] ?? 0);
var pageFolderName = VirtualPathUtility.AppendTrailingSlash(id.ToString());
var path = VirtualPathUtilityEx.Combine(provider.VirtualPathRoot, pageFolderName);
if (provider.DirectoryExists(path))
{
UnifiedDirectory vdir = (UnifiedDirectory)provider.GetDirectory(path);
...
I was looking at a similar code while I waited for a reply and I can't find what namespace to use for VirtualPathUtilityEx. Can you help me out?
VirtualPathUtilityEx is in EPiServer.Web (Assembly: EPiServer.Framework in CMS 6) and VirtualPathUtility is in System.Web.
Edit: Assembly name
I was hoping that EPiServer.Web wouldn't be the answer. I've already added that. :/
How do I know if I'm using the CMS6 assembly?
Edit: Never mind, I found it.
Exactly, that's what I'd forgotten.
The code I'm using right now is this. It says the directory doesn't exist and skips the adding of the files. Should the PageFolderID be the same as the PageID? In this case they aren't.
VirtualPathUnifiedProvider provider = (VirtualPathUnifiedProvider)VirtualPathHandler.GetProvider("SiteGlobalFiles");
var id = (int)(CurrentPage["PageFolderID"] ?? 0);
var pageFolderName = VirtualPathUtility.AppendTrailingSlash(id.ToString());
var path = VirtualPathUtilityEx.Combine(provider.VirtualPathRoot, pageFolderName);
if (provider.DirectoryExists(path))
{
UnifiedDirectory vdir = (UnifiedDirectory)provider.GetDirectory(path);
DDL1.DataTextField = "Name"; //Show the filenames in the dropdown list
DDL1.DataValueField = "VirtualPath"; //And keep their virtual path as the key
DDL1.DataSource = vdir.GetFiles();
}
this.DataBind();
Does the folder exist for the page in question? It is only created if the editor has selected to do so, so quite possibly many pages could be lacking a page folder.
I'm trying to list the page files of a certain page and I found this blog post. http://labs.episerver.com/en/Blogs/Allan/Dates/111319/111320/File-Selection-Drop-Down-List/ When I use "SiteDocuments", like Allan does in his example code, everything works great. However, when changing to "SitePageFiles" I get an empty list. The code runs and says the directory exists but I don't get a list of the 7-8 files that are located in the pages folder.
Any ideas?