AI OnAI Off
Enter the id (numeric) of the page you want to export child pages
from.
Note! The process can take some time to run, be
patient.
ID of Parent:
The exported file will be saved to: "/upload/exported.epi4"
In the code behind file, hook up the cmdExport button:
private void InitializeComponent()
{
this.cmdExport.Click += new System.EventHandler(this.cmdExport_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
In Page_Load, you can set the timeout:
private void Page_Load(object sender, System.EventArgs e)
{
// Script timeout 1 hour
this.Server.ScriptTimeout = 3600;
}
The main part is the export process:
private void cmdExport_Click(object sender, System.EventArgs e)
{
int id = int.Parse(txtIdOfParent.Text);
PageReference pageRef = new PageReference(id);
PageData PageRoot = Global.EPDataFactory.GetPage(pageRef);
DataExporter exporter = new DataExporter();
exporter.AllowPageSync = true;
exporter.IgnorePageHierarchy = false;
// We need to add all pages, but we add them as pagereferences, not pagedata objects as they will be
// loaded as raw pages.
PageReferenceCollection childRefCol = new PageReferenceCollection();
PageDataCollection childPages = EPiServer.Global.EPDataFactory.GetChildren(pageRef, AccessControlList.NoAccess);
foreach(PageData pd in childPages)
childRefCol.Add(pd.PageLink);
PageReference[] childs = childRefCol.ToArray();
childRefCol = null;
// This runs faster, but uses undocumentet features, which could change in a later version
//PageReference[] childs = new EPiServer.DataAccess.PageListDB().ListAll(pageRef);
PageReference rootPage = PageRoot.PageLink;
rootPage.LoadRawPageData = true;
exporter.DestinationPages.Add(Global.EPDataFactory.GetPage(rootPage, AccessControlList.NoAccess));
foreach(PageReference pageReference in childs)
{
PageReference loadRaw = pageReference;
loadRaw.LoadRawPageData = true;
exporter.DestinationPages.Add(EPiServer.Global.EPDataFactory.GetPage(loadRaw, AccessControlList.NoAccess));
}
FileStream strm = new FileStream(HttpContext.Current.Server.MapPath("~/upload/exported.epi4"), FileMode.CreateNew);
exporter.Stream = strm;
exporter.Export();
strm.Close();
lblStatus.Text += "Done
";
foreach(string str in exporter.ProgressLog)
lblStatus.Text += str + "
";
}
You also need the following namespaces:
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAccess;
using EPiServer.Enterprise;
using EPiServer.Security;
using System.IO;
/Steve