Save page

Namespace:  EPiServer
Assembly:  EPiServer (in EPiServer.dll) Version: 5.2.375.236


public PageReference Save(
	PageData page,
	SaveAction action


Type: EPiServer.Core..::.PageData
An initialized PageData object containing data to be saved
Type: EPiServer.DataAccess..::.SaveAction
Action that will be performed


Note: The action parameter is a SaveAction enumeration that is located in a non-documented part of the SDK. You can however use it as it is a part of the EPiServer API and available from code.

If PageLink is empty a new page will be created

Access right required:


The following example shows how to programmatically create a page.
<%@ Page Language="c#" Codebehind="createPage.aspx.cs" AutoEventWireup="false" Inherits="development.createPage"
    EnableViewState="False" EnableSessionState="True" %>

<%@ Register TagPrefix="EPiServer" Namespace="EPiServer.WebControls" Assembly="EPiServer" %>
    <title>Creates a page programatically</title>
    <form id="createPage" method="post" runat="server">
        <input type="hidden" id="selectedPageLink" name="selectedPageLink" runat="server">
        <input type="hidden" id="selectedPageName" name="selectedPageName">
        <b>Where do you want to create the new page:</b><br>
        <EPiServer:PageDataSource runat="server" ID="Pages" PageLink="<%#EPiServer.Core.PageReference.StartPage%>"
            IncludeRootPage="true" EnableVisibleInMenu="false" />
        <asp:TreeView runat="server" ID="PageTree" DataSourceID="Pages" MaxDataBindDepth="5"
            ShowExpandCollapse="true" ExpandDepth="0" SelectedNodeStyle-BackColor="lightgray"
                <asp:TreeNodeBinding SelectAction="SelectExpand" TextField="PageName" ValueField="PageLink" />
        Parent id:<br />
        <asp:TextBox ID="parentId" runat="server" MaxLength="3"></asp:TextBox>
        <br />
        Name:<br />
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="cmdCreatePage" runat="server" Text="Create Page"></asp:Button>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAbstraction;

namespace development
    /// <summary>
    /// Summary description for createPage this page should be located in some directory .
    /// </summary>
    public class createPage : EPiServer.SimplePage
        protected System.Web.UI.WebControls.TreeView PageTree;
        protected System.Web.UI.WebControls.Button cmdCreatePage;
        protected System.Web.UI.WebControls.TextBox txtName;
        protected System.Web.UI.WebControls.TextBox parentId;

        private void cmdCreatePage_Click(object sender, System.EventArgs e)
            PageType pageType = PageType.Load("[Public] Standard page");
            int id = PageReference.StartPage.ID;

            Int32.TryParse(parentId.Text, out id);
            PageReference parent = new PageReference(id);
            // You can find the ID of the page type by hoovering the mouse 
            // over the page type link in admin mode.
            PageData newPage = DataFactory.Instance.GetDefaultPageData(parent, pageType.ID);
            newPage.PageName = txtName.Text;

            ((PropertyLongString)newPage.Property["MainBody"]).Value = "This text was        <font color=red>autogenerated</font>.";

            // Save. Note the EPiServer.DataAccess.SaveAction enum is not documented
            DataFactory.Instance.Save(newPage, EPiServer.DataAccess.SaveAction.Publish);
            newPage.LinkURL = UriSupport.BuildUrlWithPageReference(newPage.LinkURL, newPage.PageLink);
            Response.Write("Saved new page with the page identity = '" + newPage.PageLink.ID + "'<br>");
            Response.Write("The link to the new page is: <a href=\"" + newPage.LinkURL + "\">" + newPage.LinkURL + "</a>");

        protected void PageTreeSelect(object sender, EventArgs e)
            parentId.Text = PageTree.SelectedNode.Value;

        private void Page_Load(object sender, System.EventArgs e)
            // Put user code to initialize the page here

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
            this.Load += new EventHandler(this.Page_Load);
            this.cmdCreatePage.Click += new EventHandler(this.cmdCreatePage_Click);


The following example shows how to edit and save en existing page.
PageData data;
DataFactory factory = EPiServer.DataFactory.Instance;
data = factory.GetPage(EPiServer.Core.PageReference.StartPage);

// This will add todays date after the name
data.PageName += " " + DateTime.Now.ToShortDateString();
// Save and publish
factory.Save(data, EPiServer.DataAccess.SaveAction.Publish);


EPiServer.Core..::.AccessDeniedException Thrown AccessDeniedException when user doesn't have enough access rights to perform this action

See Also