Difference between create a new page or copy an existing page

Vote:
 

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

#147053
Apr 05, 2016 12:37
Vote:
 

Hi,

Try to execute safety cast eventArgs to CopyContentEventArgs:

bool isCopy = eventArgs as CopyContentEventArgs;
#147057
Edited, Apr 05, 2016 13:18
Vote:
 

I can't get that to work.

I link event with:

contentEvents.CreatedContent += contentEvents_CreatedContent;
public void contentEvents_CreatedContent(object sender, EPiServer.ContentEventArgs e)
{
...
}




#147058
Apr 05, 2016 13:25
Vote:
 

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.

#147154
Apr 07, 2016 9:11
Vote:
 

Strange,

I added the code, but the 'copyContentEventArgs' variable still returns a null-value after a copy/paste action.

Thanks for checking it,

Ron

#147234
Apr 08, 2016 10:50
Vote:
 

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,

#207984
Oct 09, 2019 16:58
Vote:
 

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

#207988
Oct 09, 2019 19:21
Vote:
 

Thanks for you reply!,

but this is strange... on my side, CopyContentEventArgs is always null...

#207990
Oct 09, 2019 20:18
Vote:
 

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.

#207991
Oct 09, 2019 20:50
Vote:
 

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

#207992
Oct 09, 2019 21:40
Vote:
 

Sounds good, now you can mark Grzegorz's answer accepted. That will help other developers find solution to similar problems. :)

#207993
Edited, Oct 09, 2019 22:21