Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rob Smith 34 posts 165 karma points
    Jun 11, 2013 @ 10:59
    Rob Smith
    0

    Umbraco 4.8.1 copy event - finding the ID of the new copied node

    I am writing my first bit of event code here, so the below is a bit rough around the edges but I need to find out the ID of the node that has been created during a copy event.

    I thought it would be:

    sender.Id

    But that is the node it has been copied from

    Does anyone know how to get the ID of the newly created node?

    namespace EventSamples
    {
        public class TestEventHandle2 : umbraco.BusinessLogic.ApplicationBase
        {
            public TestEventHandle2()
            {
                Document.AfterCopy += new Document.CopyEventHandler(Document_AfterCopy);
            }
            void Document_AfterCopy(Document sender, umbraco.cms.businesslogic.CopyEventArgs e) {
     
                // Execute Some Logic Here.
    // get the content type of the published document
    var docType = sender.ContentType;
    //this only works with items that are publshed as a course
    if(docType.Alias == "Course")
    {
    //work out our vars
    string a = DateTime.Now.ToString("yyMMddhhmm");
    int oldid = Convert.ToInt32(a); //THIS updates the OLD node sender.getProperty("oldid").Value = oldid.ToString();

    //we need the new nodes ID
    int newNode = sender.Id;

    //add to logs
    Log.Add(LogTypes.Copy, sender.Id, "Course Copied and saved and added to ");

    }
            }
        }
    }
  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Jun 11, 2013 @ 11:27
    Dave Woestenborghs
    0

    Sender is the original document

    You can get the new Document from the CopyEventArgs

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft