AI OnAI Off
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).
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.