Get a list of page files from the file manager

Vote:
 

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?

#49504
Mar 22, 2011 9:22
Vote:
 

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.

#49506
Mar 22, 2011 10:15
Vote:
 

Yeah, what I don't get about that is how to use it in the code. What part should I change?

#49507
Mar 22, 2011 10:26
Vote:
 

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

...

#49508
Mar 22, 2011 10:36
Vote:
 

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?

#49509
Mar 22, 2011 10:43
Vote:
 

VirtualPathUtilityEx is in EPiServer.Web (Assembly: EPiServer.Framework in CMS 6) and VirtualPathUtility is in System.Web.

Edit: Assembly name

#49510
Edited, Mar 22, 2011 10:44
Vote:
 

I was hoping that EPiServer.Web wouldn't be the answer. I've already added that. :/

#49512
Mar 22, 2011 10:46
Vote:
 

How do I know if I'm using the CMS6 assembly?

Edit: Never mind, I found it.

#49513
Edited, Mar 22, 2011 10:52
Vote:
 

If you have it referenced, it's for CMS 6 (it didn't exist in CMS 5)

#49514
Mar 22, 2011 11:00
Vote:
 

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();

#49516
Mar 22, 2011 11:05
Vote:
 

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.

#49517
Mar 22, 2011 11:06
Vote:
 

Yes, the folder exists but I noticed it still said SiteGlobalFiles instead of SitePageFiles.

Thanks a million for all your help!

#49519
Mar 22, 2011 11:08
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.