November Happy Hour will be moved to Thursday December 5th.

Create page programatically and save

Vote:
 

I want to create a copy of a page when it is publish and create the copy on same other location in the site.

I add below code

 

DataFactory.Instance.PublishedPage += new PageEventHandler(Instance_PublishedPage) , so that event is fired only

whenever page is published.

private void Instance_PublishedPage(object sender, PageEventArgs e)
{


     PageData page = e.Page;

     if (page["PublishtoSales"] != null && (bool)page.Property["PublishtoSales"].Value == true)
     {
       CreatePageonSales(page);
     }

}

This code is called more then once for each publish and create many copies under parent page.

CreatePageonSales(page) function just create a page and Saves it.

#88735
Jul 28, 2014 18:03
Vote:
 

I do not know how your method CreatePageonSales looks but from the description I guess you create a clone and then call Save(page, SaveAction.Publish)? What will happen then is that the Published event is raised again (for your new "copy") which triggers a new page and so on...

One option is to call IContentRepository.Copy instead of calling Save(page, SaveAction.Publish).

Another option (if you e.g. need to set some properties on the"copied" page) is to look att page.ParentLink in the eventhandler. And only call CreatePageonSales if ParentLink differs from the "other location" (meaning it is not your CreatePageonSales that has triggered the publish event).

#88746
Jul 29, 2014 8:15
Vote:
 

Thanks Johan for the reply!!!

#88771
Jul 30, 2014 11:00
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.