November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
UnifiedFile file = UnifiedFileSystem.GetFile(path);
now in cms 5:
UnifiedFile uf = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(path) as UnifiedFile;
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.
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
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
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?