ICSAsyncEventHandlerEventHandler Method Content Studio 5.7 SDK
Content Studio Web Content Management System

[This is preliminary documentation and is subject to change.]

Defines an asynchronous Content Studio event handler. Objects that implement this interface can act as an event handler for asynchronous events.

Namespace: ContentStudio.EventActions
Assembly: CS5Interfaces (in CS5Interfaces.dll) Version: (

void EventHandler(
	int csEvent,
	int connectionId,
	string eventXMLArguments,
	string customData,
	ICSCredentialsContainer credentials,
	int timeOut,
	out string statusText


Type: SystemInt32
The event that triggered the job being executed. The value of these events are defined in the ContentStudioEvents
Type: SystemInt32
A value that identifies the site.
Type: SystemString
Data that contains standard event data passed to the implementation by the Content Studio API. The exact syntax of this xml can vary between different events and versions of Content Studio but this sample can act as a guideline. The sample is typical for a document event (ex. OnDocumentSave or OnDocumentApprove).

   <!-- Standard elements that exists for any event -->
   <msgid>String value</msgid>
   <timestamp>DateTime string value</timestamp>
   <sessionid>Int32 value</sessionid>
   <userid>Int32 value</userid>
   <username>String value</username>
   <fullname>String value</fullname>
   <!-- Elements that exists for document events -->
   <documentid>Int32 value</documentid>
   <documentname>String value</documentname>
   <filename>String value</filename>
   <encoding>String value</encoding>
   <categoryid>Int32 value</categoryid>
   <documenttitle>String value</documenttitle>
Element nameDescription
msgidAn identifier of this specific message
timestampDate and time of the event
sessionidAn identifier of the session that raised the event. This value can be invalid at the time the event is handled.
useridThe internal identifier of the user that triggered the event.
usernameThe login name of the user that triggered the event. This name is in the traditional Windows format (DOMAIN\USERNAME)
fullnameThe full name of the user that triggered the event (ex. John Smith or Smith, John depending on how the authority displays the name).
documentidAn identifier to the document affected by this event.
documentnameThe logical file name of the affected document (ex. Unit1/Category1/pic1.gif).
filenameThe file name of the affected document as it appears on disc.
encodingThe encoding (ex. utf-8), if existing, of the affected document.
categoryidAn identifier of the category where the affected document is placed.
documenttitleThe name of the affected document.
Type: SystemString
User defined data that has been specified for the Event action definition that triggered this event. This data is entered in the Command field in the Event actions definition window and has different meaning for different events.
Type: ContentStudio.EventActionsICSCredentialsContainer
A reference to Content Studio's implementation of the ICSCredentialsContainer interface. This interface is used to pass system defined credentials to the custom implementation.
Type: SystemInt32
A timeout value (in seconds) to use. When zero is passed in the implementation should use a default time out value ex. 30 seconds to avoid hung event handlers.
Type: SystemString
A status message after the call the implementer can use to notify Service Manager. This message will be logged on success.

Note Note

Breaking changes between Content Studio version 5.2 and earlier versions!

This interface is no longer defined in the CSServer5 assembly, instead it has been moved into a separate assembly in order to prevent versioning problems for compiled code that implement them when a new version of Content Studio. Compiled event handlers needed to be recompiled after each upgrade of the product. This will no longer be required.

Also, the csEvent parameter of the EventHandler method has been changed from an enumeration to an Int32 in order to make it possible to add more events in the future.


Custom implementation should throw exceptions if the event handler fails. Any exception will be handled by the Service Manager and logged in the Content Studio event log.

This code example shows a full implementation of an event handler, explicitly implementing ICSAsyncEventHandler that sends mail to one or more e-mail receivers.
  • Compile the class as an assembly (ex. TheEventHandler.dll assembly name: TheEventHandler)
  • Copy the dll to the installation directory of the Content Studio binaries (ex. C:\Program Files\Teknikhuset\ContentStudio\CSServer).
  • In Content Studio on a certain category, add a new Event Actions handler (ex. OnDocumentApprove) and set the type to be Asynchronous Event hander.
  • In the ProgID field, enter the full name of the class and the assembly name in the format "NAMESPACE.CLASS, ASSEMBLY" (in this case "TheCompany.TheNamespace.CustomEventHandler, TheEventHandler")
  • As an alternative you can install your assembly in the global assembly cache but in this case you must provide more detailed assembly information to Content Studio. See the MSDN documentation for more information on how to use the Activator class.
  • In the command window add a semicolon-separated list of mail addresses that should receive the resulting mail message.
The implementation should set an informative message in the StatusText output parameter that should be logged by the Service Manager after a successful call.

using System;
using System.Xml;
using System.Data;
using System.Data.SqlClient;
using ContentStudio.Document;

namespace TheCompany.TheNamespace
  public class CustomEventHandler : ICSAsyncEventHandler
     #region ICSAsyncEventHandler Members
     void ICSAsyncEventHandler.EventHandler(int csEvent,
                                            int connectionID,
                                            string eventXMLArguments,
                                            string customData,
                                            ICSCredentialsContainer credentials,
                                            int timeOut,
                                            out string statusText)
         //Get the document name and some other useful data from the csEventXmlArguments
         //passed in by the Service Manager.
         string documentName = "", username = "";
         int documentID = 0, categoryid = 0;
         using (StringReader sr = new StringReader(eventXMLArguments))
             XmlReader XReader = XmlReader.Create(sr);
             int found = 0;
             while (XReader.Read())
               if (XReader.NodeType != XmlNodeType.Element)
                 switch (XReader.Name)
                     case "documentid":
                         Int32.TryParse(XReader.ReadString(), out documentID);
                     case "documentname":
                         documentName = XReader.ReadString();
                     case "categoryid":
                         Int32.TryParse(XReader.ReadString(), out categoryid);
                     case "username":
                         username = XReader.ReadString();
                 if (found == 4)
                     //all four intresting values are found
         statusText = "Sending mail info regarding " + documentName + " (" + documentID.ToString() + ")";
         //Build a message to send
         string message = "Content Studio " + csEvent.ToString() + ":" + Environment.NewLine
                          + documentName + " (" + documentID.ToString() + ") in category " 
                          + " (" + categoryid.ToString() + ") has been manipulated by " + username;
         //in this case we send the message to the receivers in the CustomData field
         System.Net.Mail.MailMessage Msg = new System.Net.Mail.MailMessage();
         Msg.Sender = new System.Net.Mail.MailAddress("Info@thecompany.nu");
         Msg.From = Msg.Sender;
         Msg.Subject = "A Content Studio custom event has sent this message to you!";
         Msg.Body = message;
         //Add all recipients
         string[] recipients = CustomData.Split(';');
         foreach (string r in recipients)
         //Send the message through a mail server named "POSTMAN".
         System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("POSTMAN");
See Also


Other Resources