November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Andreas Nicolaisen at EPiNova created a blog post about a similar function:
http://www.epinova.no/blog/andreas-nicolaisen/dates/2011/9/create-your-own-copy-page-event/
I'm not certain if you can put it on the CreatedPage event or if it really needs to be on the PublishedPage since you might copy an unpublished Page.
The key is that e.Page should be null.
Thank Alf. I tried this but it would not work. The problem is that the name does not change in treeview before the user publishes the page. Any solution for this?
As I mentioned, I'm not sure whether you can change this to hookup to the CreatedPage event instead.
Could you change and see if this would add the name on create instead of publish?
Yeah might even be better and then I guess you don't need to save the page separately.
Unfortunately I'm not able to try this out myself at the moment so all I can give are hints.
Thank you both. I have actually used CreatedPage. The problem with using CreatingPage is that the Page property in PageEventArgs (CopyPageEventArgs) passed to CreatingPage is null so is PageLink. There is a SourceLink property which has the link to the page that is being copied but I would have to do the copying myself and it might get messy.
HI Reza,
would it be possible to add a snippet of how you did this... because if you hook into the createdPage event, how did you check if this was a new page or a copied page of an existing page..
This if what i have for now
[InitializableModule] public class DataFactorySubscriber : IInitializableModule { public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context) { context.InitComplete += InitComplete; } private static void InitComplete(object sender, EventArgs e) { DataFactory.Instance.CreatedContent += CreatedContent; } private static void CreatedContent(object sender, ContentEventArgs e) { var content = e.Content; if (content != null) { CreateCopyPage(e.ContentLink); } } private static void CreateCopyPage(ContentReference contentLink) { var repo = ServiceLocator.Current.GetInstance<IContentRepository>(); //check if exists bool alreadyExists = repo.Get<PageData>(contentLink).GetSiblings().Where(p => p.Name == repo.Get<PageData>(contentLink).Name).Any(); if (!alreadyExists) { return; } var variant = repo.Get<PageData>(contentLink); var clone = variant.CreateWritableClone(); clone.PageName = variant.Name + " - Copy"; clone.URLSegment = ""; // Does this page have a simple address? //clone.SetPropertyValue(p => p.URLSegment, ""); DataFactory.Instance.Save(clone, SaveAction.Save, AccessLevel.NoAccess); } public void Uninitialize(EPiServer.Framework.Initialization.InitializationEngine context) { context.InitComplete -= InitComplete; DataFactory.Instance.CreatedContent -= CreatedContent; } public void Preload(string[] parameters) { } }
The problem is two fold: It was first complaining that the URL in Name is already in use. So i set the URLSegment to "" .
But still my copied page doesnt get the new pageName with -Copy behind it. And this fails completely if there the page being copied containt contentassetfolders (blocks for example).
What would be a correct way to rename a copied page (with or without assets) from code?
I was wondering if there is any way to append a text at the end of the copied page name to avoid confusion, so once user copies a page with name "Test" , the dupicated page has a name as "Test-Copy" .