Try our conversational search powered by Generative AI!

Create directory using GetDefaultDirectory(true)


Hi there.

I´m trying to create pages and upload images to the unified file system programatically from outside the EPiServer admin.

Creating the pages work fine but not uploading the images. When i try to create a new directory using the PageData.GetPageDirectory(true)-method it throws an unauthorization exception.

Is there a way to set the accesslevel on the page so that I can create a dictionary and upload files?

Some code:

PageData page = DataFactory.Instance.GetDefaultPageData(container, 123);
page.PageName = txtHeadline.Text;

DataFactory.Instance.Save(page, EPiServer.DataAccess.SaveAction.Save,

UnifiedDirectory directory = page.GetPageDirectory(true);
UnifiedFile file = directory.CreateFile(fileUpload.FileName);
Stream stream = file.Open(FileMode.CreateNew);
StreamConsumer.CopyToEnd(fileUpload.FileContent, stream);



Thanks a bunch.

Oct 28, 2008 11:03

You can bypass the access checking by adding:

directory.BypassAccessCheck = true;


Jun 05, 2009 9:16
* 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.