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