London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Page folder in CMS

Vote:
 
I'm converting a 4.61 to CMS and have a question regarding file handling. I need to browse thru a page folder and get any files of a specific type. In the old version I do like this: UnifiedDirectory pageDir = UnifiedPageDirectory.Get(CurrentPage.PageLink); if (pageDir == null) pageDir = UnifiedPageDirectory.Create(CurrentPage.PageLink); ... UnifiedDirectory thumbsDir = pageDir.GetSubdirectory(ThumbsDirName); ... UnifiedFile[] thumbs = thumbsDir.GetFiles((string)Global.EPConfig["EPsFilePattern"]); Can anyone describe to me how this is done in CMS?
#15778
Sep 21, 2007 11:34
Vote:
 
Hi, This is now Virtual path providers in CMS 5. We have a sample code about it (but it is written in april and things could have changed since): http://www.episerver.com/EPiServerCom/Templates/SampleSource.aspx?id=11336&epslanguage=EN Also a technote about VPP: http://www.episerver.com/en/EPiServer_Knowledge_Center/Documentation/TechNotes/CMS-Tech-Notes/Virtual-Path-Providers-in-EPiServer/ But the best source of information is the sdk (sdk.episerver.com). Look at the EPiServer.web.hosting namespace. For example in episerver 4 you wrote: UnifiedFile file = UnifiedFileSystem.GetFile(path); now in cms 5: UnifiedFile uf = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(path) as UnifiedFile;
#16341
Sep 21, 2007 17:34
Vote:
 
I think the question that the answerer is cleverly dodging here really is: Is there a command to get the virtual path for the current EPiServer page? Previously, you could insert a PageReference as an argument to the UnifiedPageDirectory.Get() method and the path would resolve itself from there, but the EPi-intrisic method has now been removed in favor of the more generic System.Web.Hosting library. So, what to put in there instead, as an argument to System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile()? CurrentPage.LinkURL did not work for me.
#16342
Sep 24, 2007 13:15
Vote:
 
Hi As you said in EPiServer CMS 5 we have adopted the VirtualPathProvider API. The way to get a directory (in your case a Page folder) in this API is to call System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetDirectory(virtualpath). So to get a pagefolder you need to pass in the virtualpath for the pagedirectory in the above statement. This is unfortunately not so obvious how to construct that. Below is a solution for this: using System.Web.Hosting; using EPiServer.Web.Hosting; string pageFolderPath = VirtualPathUtility.AppendTrailingSlash(VirtualPathHandler.PageDirectoryRootVirtualPath + CurrentPage["PageFolderID"]); VirtualDirectory pageDir = HostingEnvironment.VirtualPathProvider.GetDirectory(pageFolderPath); I have added an issue in our bug system that we should offer a more convenient way of getting page folder, e.g. by offer a Property PageFolder on PageData.
#16343
Oct 02, 2007 7:57
Vote:
 
Getting a handle to an existing file: UnifiedFile file = HostingEnvironment.VirtualPathProvider.GetFile(virtualPath) as UnifiedFile; Get or Create a Page Folder: int folderId = (int) page.Property["PageFolderID"].Value; string pageDirectoryRootVirtualPath = VirtualPathHandler.PageDirectoryRootVirtualPath; IPageDirectory pageDirectory = HostingEnvironment.VirtualPathProvider.GetDirectory(pageDirectoryRootVirtualPath) as IPageDirectory; string virtualPathFromFolderId = VirtualPathUtilityEx.Combine(pageDirectoryRootVirtualPath, VirtualPathUtility.AppendTrailingSlash(folderId.ToString())); UnifiedDirectory directory = HostingEnvironment.VirtualPathProvider.GetDirectory(virtualPathFromFolderId) as UnifiedDirectory; if (directory == null) { directory = pageDirectory.CreateSubdirectory(folderId.ToString(), page); } NOTE! Folder will not “exist” for real until a file is saved inside it. It is important to call CreateSubdirectory with the page as parameter to setup security correctly! Getting a handle to a new file: UnifiedFile file = HostingEnvironment.VirtualPathProvider.GetFile(virtualPath) as UnifiedFile; if (file == null) { string virtualDir = VirtualPathUtility.GetDirectory(virtualPath); UnifiedDirectory directory = HostingEnvironment.VirtualPathProvider.GetDirectory(virtualDir) as UnifiedDirectory; return directory.CreateFile(VirtualPathUtility.GetFileName(virtualPath)); } Example of reading UnifiedFile: Bitmap image = null; using (Stream stream = file.Open()) { image = (Bitmap) Image.FromStream(stream); } Example of writing with UnifiedFile: using (Stream stream = file.Open(FileMode.Create, FileAccess.Write)) { image.Save(stream, encoderInfo, encoderParams); } Regards, Fredrik Haglund INEXOR AB – det digitala byggbolaget ™ http://blog.fredrikhaglund.se
#16344
Nov 28, 2007 12:35
Vote:
 

Hi I was interested in the sample provided http://www.episerver.com/EPiServerCom/Templates/SampleSource.aspx?id=11336&epslanguage=EN, but there is an error opening the zip.

Can you re-provide.

Regards,

Ian

#25924
Nov 12, 2008 13:16
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.