Hi,
I have a new document type containing an image field. The document name should be the name of the image, so, I use Global Events.
When i insert a new document it works but not when I update it or with workflow operations.
[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()
{
DocumentEvents.Update.After += Document_Update_After;
}
private void Document_Update_After(object sender, DocumentEventArgs e)
{
UpdateDocumentName(e.Node);
}
private void UpdateDocumentName(TreeNode node)
{
if (node != null)
{
if (node.NodeClassName.Equals("aa.GalleryImage"))
{
var imageGuid = ValidationHelper.GetGuid(node.GetValue("ImageSrc"), Guid.Empty);
if (imageGuid == Guid.Empty) return;
var am = new AttachmentManager();
var attachment = am.GetAttachmentInfo(imageGuid, CMSContext.CurrentSiteName);
if (attachment == null) return;
node.DocumentName = attachment.AttachmentName;
node.Update();
}
}
}
}
}
Thanks for any guidance...
Regards,