Hi,
Try to execute safety cast eventArgs to CopyContentEventArgs:
bool isCopy = eventArgs as CopyContentEventArgs;
I can't get that to work.
I link event with:
contentEvents.CreatedContent += contentEvents_CreatedContent;
public void contentEvents_CreatedContent(object sender, EPiServer.ContentEventArgs e) {
...
}
Hi,
I just tested it on Alloy demo and it works:
using EPiServer.Core; using EPiServer.Framework; using EPiServer.SpecializedProperties; using ContentAreaWithPreview.Business.WebControls; using EPiServer; using EPiServer.Framework.Initialization; using EPiServer.Logging; using EPiServer.ServiceLocation; namespace ContentAreaWithPreview.Business.Initialization { [InitializableModule] [ModuleDependency(typeof(EPiServer.Web.InitializationModule))] public class TestInitialization : IInitializableModule { public void Initialize(InitializationEngine context) { var contentEvents = ServiceLocator.Current.GetInstance<IContentEvents>(); contentEvents.CreatedContent += ClassFactoryInitialization_CreatedContent; } private static readonly ILogger _logger = LogManager.GetLogger(); private void ClassFactoryInitialization_CreatedContent(object sender, EPiServer.ContentEventArgs e) { var copyContentEventArgs = e as CopyContentEventArgs; if (copyContentEventArgs != null) { _logger.Debug("Copy content from {0}...", copyContentEventArgs.SourceContentLink); } } public void Uninitialize(InitializationEngine context) { } } }
During copying the event is executed few times.
Strange,
I added the code, but the 'copyContentEventArgs' variable still returns a null-value after a copy/paste action.
Thanks for checking it,
Ron
3 Years later..... but i have the same issue. i'm trying to initialize some field in the CreatedContent when a user copy/paste a page. Maybe it's not THE place to do this operation.... But my CopyContentEventArgs is always null. and impossible to update values since everything except the PageName seem to be null.....
Any help would be highly appreciated! Thanks,
Hi Christian,
I have tested above code and verified that, and it is working for me too, you just need to get item with content loader as PageData to read any property.
I copied and pasted Alloy Plan page.
Here you can see full list of data loaded in debug mode
Thanks for you reply!,
but this is strange... on my side, CopyContentEventArgs is always null...
So, it hits multiple times in ClassFactoryInitialization_ContentCreated method. You need to hit until you get into if condition. Is that not going into if statement for you when you paste your copied page?
If that's the case, I would like to know if you are testing in Alloy or other project? I will confirm if I also face that in other project.
ohhh, got it. We are a couple of developers on the same azure service bus (Dev environment). And i think maybe the problem was due to multiple dev debugging at the same time... anyway, it working!
Thanks a lot Praful
Sounds good, now you can mark Grzegorz's answer accepted. That will help other developers find solution to similar problems. :)
Hi everyone,
I'm using the CreatedContent event and trying to check if the created page is a brand new page or just a page created by Copy-Paste of an existing page. How can i spot the difference in code between the two?
Thanks in advance,
Ron