Copy a page to another container served by the same page provider.

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

Syntax

C#
public virtual PageReference Copy(
	PageReference pageLink,
	PageReference destinationLink,
	bool publishOnDestination,
	bool allowThreading
)

Parameters

pageLink
Type: EPiServer.Core..::.PageReference
The link to the page to copy.
destinationLink
Type: EPiServer.Core..::.PageReference
The container where the page will be copied
publishOnDestination
Type: System..::.Boolean
If the new pages should be published on the destination
allowThreading
Type: System..::.Boolean
Run the local copy process on a separate thread (don't work for remote sites).

Return Value

Implements

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

Remarks

Copy between page provider instances is to be seen as a Create at destination provider. If copy is to be supported this method needs to be overriden.

Note, when a page is copied successfully the CreatedPage event is fired, since a page is created in the copy process. But in contrast to the Save method, that also fires the CreatedPage method and always passes an initialized PageData object in the PageEventArgs object to the event handler, the Copy method does not. Instead it only passes a pagereference to the copied page and it is up to the handler to load the page data. The reason for this behavior in the Copy method is performance.

Examples

The following code sample is an implementation of Copy() for XmlPageProvider.
CopyC#
public override PageReference Copy(PageReference pageLink, PageReference destinationLink, bool publishOnDestination, bool allowThreading)
{
    // 
    //Copy is implemented as making a clone of existing page and give it new identity
    Guid newGuid = Guid.NewGuid();
    // 
    //Start with the master language branch
    PageData orgPage = GetPage(pageLink, LanguageSelector.MasterLanguage());
    PageData copy = orgPage.CreateWritableClone();
    copy.PageLink = PageReference.EmptyReference;
    copy.PageGuid = newGuid;
    copy.ParentLink = destinationLink;

    PageReference newIdentityRef = Save(copy, publishOnDestination || orgPage.CheckPublishedStatus(PagePublishedStatus.Published) ? SaveAction.Publish : SaveAction.Save);
    // 
    //Now create all other langauges (if they exist)
    foreach (string lang in orgPage.PageLanguages)
    {
        PageData langPage = GetPage(pageLink, new LanguageSelector(lang));
        if (langPage.IsMasterLanguageBranch)
        {
            continue;
        }
        copy = langPage.CreateWritableClone();
        copy.PageLink = newIdentityRef;
        copy.PageGuid = newGuid;
        copy.ParentLink = destinationLink;

        Save(copy, publishOnDestination || langPage.CheckPublishedStatus(PagePublishedStatus.Published) ? SaveAction.Publish : SaveAction.Save);
    }
    // 
    // get list of all children
    PageReferenceCollection children = GetChildrenReferences(pageLink, null);
    // 
    // check if descendant nodes can be copied
    if (ShouldCopyChildren(destinationLink,children))
    {
        // 
        // recursively copy all children
        foreach (PageReference child in children)
        {
            Copy(child, newIdentityRef, publishOnDestination, allowThreading);
        }
    }
    return newIdentityRef;
}

Exceptions

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

See Also