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 "); } } } }
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?
Sender is the original document
You can get the new Document from the CopyEventArgs
Dave
is working on a reply...