This handler allows you to add custom actions to the following events:
The events are applied to all data items that are stored to the database. It includes documents, user information or any other settings. They receive the data object of type DataClass that can be modified. In case of delete handlers, the class name and ID is provided.
Handling document events
For handling document events, please use the CustomTreeNodeHandler class instead of the CustomDataHandler class. Every document uses up to 3 tables, which leads to three separate events in the CustomDataHandler class.
The following example shows how to handle the OnAfterUpdate event and send the password to the user whenever their profile is updated:
1.Open the CustomDataHandler class and put the following code at the beginning of the file. It adds the reference to the namespaces we will use to handle the event:
2.Put the following code inside the OnAfterUpdate method.
// type the data object as DataClass
IDataClass dataItem = (IDataClass)dataObj;
// we want to handle only updates of user objects
if (dataItem.ClassName.ToLower() == "cms.user")
// we will use the CMS.EmailProvider to send e-mails
EmailMessage email = new EmailMessage();
email.From = "email@example.com";
// get the user's e-mail address
email.Recipients = ValidationHelper.GetString(dataItem.GetValue("Email"), "firstname.lastname@example.org");
email.Subject = "Your password";
// get the user's password
email.Body = "Your password is:" + ValidationHelper.GetString(dataItem.GetValue("UserPassword"), "");
Please note: getting user's password in the example above is only possible when passwords are stored in Plain text format; the setting is located in Site Manager -> Settings -> Security & Mebership.
3.Set the From and Recipients e-mail addresses to your e-mail address.
4. If you don't have refference to CMS.EmailEngine in your CustomEventHandler, add it there.
5. Compile and run the project. Edit some user profile that uses your e-mail address. You should receive the e-mail message with your password.