API
Version 7.x > API > Document Handler View modes: 
User avatar
Member
Member
Luca - 11/14/2013 11:13:52 AM
   
Document Handler
Is there a way to define a Handler class for document events?

Events like: document Created, Updating,Updated, deleting

I tried the following code but event not firing
    [ClassLoader]
public partial class DocumentEventHandler : CMSModuleLoader
{
private class ClassLoader : CMSLoaderAttribute
{

/// <summary>
/// Called automatically when the application starts
/// </summary>
public override void Init()
{
// Assigns custom handlers to the appropriate events
DocumentEvents.Insert.After += DocumentCreated;
.....
}

public static void DocumentCreated(object sender, DocumentEventArgs e)
{
//Not fired
}
....

thanks

User avatar
Member
Member
kentico_sandroj - 11/14/2013 4:10:47 PM
   
RE:Document Handler
Hello,

It is possible to handle document events with a global handers. These are the events that can be handled:

DocumentEvents - contains events fired when changes are made to documents. These events relate to the published versions of documents, refer to WorkflowEvents for actions within editing of the documents under workflow. Replaces the old CustomTreeNodeHandler.

•Insert - fired upon insertion of a new document.

•InsertNewCulture - fired upon insertion of a new document culture version.

•InsertLink - fired upon insertion of a new document link.

•Update - fired upon update of any document.

•Delete - fired upon deletion of any document.

•Move - fired upon moving of any document.

•Copy - fired upon copying of any document.

•GetContent - provides additional document content to the search indexer.

•LogChange - allows you to alter the way document changes are being logged.

The approach outlined in the documentation would look similar to the following:

using CMS.DocumentEngine;
using CMS.SettingsProvider;

[CustomDocumentEvents]
public partial class CMSModuleLoader
{
/// <summary>
/// Attribute class that ensures the loading of custom handlers
/// </summary>
private class CustomDocumentEventsAttribute : CMSLoaderAttribute
{
/// <summary>
/// Called automatically when the application starts
/// </summary>
public override void Init()
{
// Assigns custom handlers to the appropriate events
DocumentEvents.Insert.After += Document_Insert_After;
DocumentEvents.InsertLink.Before += Document_InsertLink_Before;
}

private void Document_Insert_After(object sender, DocumentEventArgs e)
{
// Add custom actions here
}

private void Document_InsertLink_Before(object sender, DocumentEventArgs e)
{
// Add custom actions here
}
}
}

Please let me know if you have any questions.

Best Regards,
Sandro

User avatar
Member
Member
Luca - 11/15/2013 4:41:32 AM
   
RE:Document Handler
Hi, Sandro

I soloved Looking at the class "SampleHandlerModuleLoader"

The example in the guide is not very clear, but i solved :)

Thanks
Luca