public class ContentEvent : ApplicationBase { public int published { get; set; } public ContentEvent() { Document.AfterPublish += new Document.PublishEventHandler(Document_AfterPublish); // Document.BeforePublish += new Document.PublishEventHandler(Document_BeforePublish); }
void Document_BeforePublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e) { if (sender.ContentType.MasterContentType == 1085) { User myUser = User.GetUser(0); //string status = sender.getProperty("status").Value.ToString(); umbraco.cms.businesslogic.ContentType ct = new umbraco.cms.businesslogic.ContentType(1105); sender.ContentType = ct; sender.ContentType.Save(); sender.Save(); umbraco.library.UpdateDocumentCache(sender.Id); //sender.Publish(myUser);
}
}
void Document_AfterPublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e) { if (published != 1) { if (sender.ContentType.MasterContentType == 1085) { User myUser = User.GetUser(4); //string status = sender.getProperty("status").Value.ToString(); umbraco.cms.businesslogic.ContentType ct = new umbraco.cms.businesslogic.ContentType(1105); sender.ContentType = ct; //sender.ContentType.Save(); //sender.m sender.Save(); published = 1; //umbraco.library.UpdateDocumentCache(sender.Id); sender.Publish(myUser);
How to change Document conteny Type using Event handler
I am trying to change content type of document using Event handler. I have tried before and after publish method but dosent seem to work..
ipublic ContentEvent()
{
// Document.AfterPublish += new Document.PublishEventHandler(Document_AfterPublish);
Document.BeforePublish += new Document.PublishEventHandler(Document_BeforePublish);
}
void Document_BeforePublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)
{
if (sender.ContentType.MasterContentType == 1085)
{
User myUser = User.GetUser(0);
//string status = sender.getProperty("status").Value.ToString();
umbraco.cms.businesslogic.ContentType ct = new umbraco.cms.businesslogic.ContentType(1107);
sender.ContentType = ct;
sender.ContentType.Save();
sender.Save();
umbraco.library.UpdateDocumentCache(sender.Id);
// sender.Publish(myUser);
}
}
Thats the code Ihave used..I tried that code in afterPublish as well but didnt work..Can anyone help me with that?
I tired this code as well
public class ContentEvent : ApplicationBase
{
public int published { get; set; }
public ContentEvent()
{
Document.AfterPublish += new Document.PublishEventHandler(Document_AfterPublish);
// Document.BeforePublish += new Document.PublishEventHandler(Document_BeforePublish);
}
void Document_BeforePublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)
{
if (sender.ContentType.MasterContentType == 1085)
{
User myUser = User.GetUser(0);
//string status = sender.getProperty("status").Value.ToString();
umbraco.cms.businesslogic.ContentType ct = new umbraco.cms.businesslogic.ContentType(1105);
sender.ContentType = ct;
sender.ContentType.Save();
sender.Save();
umbraco.library.UpdateDocumentCache(sender.Id);
//sender.Publish(myUser);
}
}
void Document_AfterPublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)
{
if (published != 1)
{
if (sender.ContentType.MasterContentType == 1085)
{
User myUser = User.GetUser(4);
//string status = sender.getProperty("status").Value.ToString();
umbraco.cms.businesslogic.ContentType ct = new umbraco.cms.businesslogic.ContentType(1105);
sender.ContentType = ct;
//sender.ContentType.Save();
//sender.m
sender.Save();
published = 1;
//umbraco.library.UpdateDocumentCache(sender.Id);
sender.Publish(myUser);
}
}
}
}
}
You can't change the content type per-say, the only way to go about it is to create a new document, copy the content across and delete the old one.
I'm pretty sure that's how this package works: http://our.umbraco.org/projects/developer-tools/doc-type-extensions
hmmm..cool...thanks
I found the solution..I wanted to change the Icon of the node base on coniditon and i thought only way is to change content type base on condition.
but then realised that i can use BaseTree_BeforeNodeRender and change the Icon on the fly
is working on a reply...