Create directory using GetDefaultDirectory(true) | Episerver Developer Community

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.

#25493 Oct 28, 2008 11:03

    You can bypass the access checking by adding:

    directory.BypassAccessCheck = true;


    #30189 Jun 05, 2009 9:16