Skip to content

Instantly share code, notes, and snippets.

@uniquelau
Created September 5, 2011 09:56
Show Gist options
  • Save uniquelau/1194602 to your computer and use it in GitHub Desktop.
Save uniquelau/1194602 to your computer and use it in GitHub Desktop.
Event Handler - Create Child Document
using System;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
using umbraco.cms.presentation.Trees;
using umbraco.interfaces;
namespace Asda.Jobs.EventHandlers
{
public class CreateDisciplinesOnComplexArticleCreation : ApplicationBase
{
public CreateDisciplinesOnComplexArticleCreation()
{
// event handler - when a new document is created.
Document.New += new Document.NewEventHandler(Document_New);
}
void Document_New(Document sender, umbraco.cms.businesslogic.NewEventArgs e)
{
// we only want to deal with document which are ComplexArticles
// this is because ComplexArticle, need to have sub page automatically generated.
if (sender.ContentType.Alias == "publicComplexArticle")
{
// let's set the correct document type first
// and we also need to create the document using the current user.
DocumentType dt = DocumentType.GetByAlias("publicDisciplineInfoProcess");
User author = User.GetCurrent();
// now let's create our document, using the above settings
Document doc = Document.MakeNew(dt.Text, dt, author, sender.Id);
// prepare for publishing
doc.Publish(author);
// publish document
umbraco.library.UpdateDocumentCache(doc.Id);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment