AI OnAI Off
For the permission error I don't know. Could it be that you have to save the page first, before trying to create the page's folder? I don't remember... Edit: Use the GetPageDirectory method of your PageData object.
To write a new file, call the CreateFile of your UnifiedDirectory. Then call Open on the returned UnifiedFile to get a Stream which you can write your bytes to.
Fantastic, thansk a lot. For anyone intersted here is the final code I used:
UnifiedDirectory directory = page.GetPageDirectory(true);
UnifiedFile _file = directory.CreateFile(Path.GetFileName(filePath));
Stream s = _file.Open(FileMode.Create, FileAccess.Write);
s.Write(file, 0, file.Length);
s.Close();
Hi all,
I'm working on a project and hope someone will be able to helpme with it.
I'm migrating a website from a custom CMS into Episerver, conmplete with lots of files. My problem is how to save the files as unified files during the import process.
First of all, with this piece of code:
PageData page = DataFactory.Instance.GetDefaultPageData(PageReference.StartPage, "Publication");
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);
}
giving me an error saying I don't have permission tocreate subdirectory
Secondly, this bit of code
WebClient client = new WebClient();
byte[] response = client.DownloadData(filePath);
gives me byte array of the file, but how do I turn this into a unified file and save it into the directory?
Any help/code sample will be greatly appreciated.
Thanks!