Delete a page from storage.

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

Syntax

C#
public virtual void Delete(
	PageReference pageLink,
	bool forceDelete
)

Parameters

pageLink
Type: EPiServer.Core..::.PageReference
The link to the page which will be deleted
forceDelete
Type: System..::.Boolean
Delete page even if being linked by other pages

Implements

IPageStore..::.Delete(PageReference, Boolean)

Remarks

If delete is to be supported this method needs to be overriden.

Examples

Here is the example of implementation for Delete
CopyC#
public override void Delete(PageReference pageLink, bool forceDelete)
{
    //First we delete children for the page
    DeleteChildren(pageLink, forceDelete);

    //Then we delete the page itself (or "pages" since it migth exist in multiple languages)
    var pageNodes = from page in XmlPages.Descendants("page")
                    where page.Attribute("id").Value == pageLink.ID.ToString()
                    select page;

    if (pageNodes == null)
    {
        throw new PageNotFoundException(pageLink);
    }

    //Set the nodes in a list that we can enumerate over and delete (we cant remove using an IEnumerable)
    List<XElement> toBeDeleted = new List<XElement>();
    foreach (XElement pageNode in pageNodes)
    {
        toBeDeleted.Add(pageNode);
    }
    for (int i = 0; i < toBeDeleted.Count; i++)
    {
        toBeDeleted[i].Remove();
    }

    XmlPages.Save(_filePath);
}

Exceptions

ExceptionCondition
System..::.NotImplementedException Thrown if the Page Provider indicates support for Delete with the Capabilities property, but does not override Move method.
System..::.NotSupportedException Thrown if the Page Provider does not support Delete functionality.

See Also