Portal Engine
Version 3.x > Portal Engine > CMS.CustomEventHandler.CustomDataHandler View modes: 
User avatar
Member
Member
enelson-drhorton - 8/9/2012 3:54:05 PM
   
CMS.CustomEventHandler.CustomDataHandler
I am using Version 5.5

In the CustomDatahandler.OnBeforeInsert, I am catching the event of an attachment being inserted into the tree node. It is of type CMS.File.

It is triggered by clicking upload, then selecting a file and hitting the OK button in the file dialog.

Thats all fine, but I am mystified in that I can't seem to tell which node is the parent at that point. The CMSContext.CurrentAliasPath is not populated at this point.

Is there a way in this event to know what my tree node context position is?
Where will I find a reference to the soon-to-be parent node?


User avatar
Member
Member
kentico_michal - 8/12/2012 2:08:02 AM
   
RE:CMS.CustomEventHandler.CustomDataHandler
Hi,

You can access the NodeID of the parent document throught the NodeID Url parameter as shown here:

int nodeid = QueryHelper.GetInteger("nodeid", 0);

Best regards,
Michal Legen

User avatar
Member
Member
enelson-drhorton - 8/13/2012 10:09:57 AM
   
RE:CMS.CustomEventHandler.CustomDataHandler
There is no nodeid in the querystring so this does not work. The querystring looks like this.......


imagewidth=200&imageheight=16&imageurl=%2fApp_Themes%2fDefault%2fImages%2fDesign%2fControls%2fDirectUploader%2fupload_new.png&innerdivhtml=Upload+file&innerdivclass=NewAttachment&innerloadingdivhtml=Uploading+%26%2346%3b%26%2346%3b%26%2346%3b&innerloadingdivclass=NewAttachmentLoading&attachmentguidcolumnname=FileAttachment&formguid=dc318ce9-d9f1-436d-9436-4912f55af13d&parentid=17592&insertmode=1&allowedextensions=pdf%3bgif%3bjpg%3bjpeg%3bpng%3bwav%3bwma%3bwmv%3bmpg%3bmpeg%3bmov%3bavi%3bswf&parentelemid=ctl00_plcContent_ucDirectUploader&islive=0&source=attachment&checkperm=0&frameid=ctl00_plcContent_ucDirectUploader_newAttachmentElem_uploaderFrame&includeinfo=1&sitename=DRHorton&hash=5e79ebfffadf1a5d57ad7f8058ec33bbc78daf1bb15dcaabf4a82f1d71771c8e

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 8/18/2012 5:32:00 PM
   
RE:CMS.CustomEventHandler.CustomDataHandler
Hi,

the ID is available on the Form tab in CMS Desk. But in case you are using custom handler, and you are inserting cms.file document you can use TreeNodeHandler instead of data handler. Then the nodeId will be available for sure.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
enelson-drhorton - 8/20/2012 11:04:27 AM
   
RE:CMS.CustomEventHandler.CustomDataHandler
Yes, the nodeid is available in the TreeNodeHandler, but details about the file type is not. Why can I not get both sets of data together? Whats the point of attachments if both of these pieces of data are not available.

I need a fix for this.

Thanks.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 8/21/2012 4:32:24 PM
   
RE:CMS.CustomEventHandler.CustomDataHandler
Hi,

in the Tree node handler is also available file guid which was uploaded:

node.GetValue("FileAttachment");


If you have the image guid, you are able to find out all information about the file (unsorted attachment):

CMS.WorkflowEngine.DocumentHelper.GetAttachment(...);


Best regards,
Ivana Tomanickova

User avatar
Member
Member
enelson-drhorton - 8/22/2012 1:42:10 PM
   
RE:CMS.CustomEventHandler.CustomDataHandler
Ok. Remember. The file is being uploaded. It is NOT yet uploaded. Thats why I was originally using CMS.CustomEventHandler.CustomDataHandler. I am catching the event prior to the upload point.

Inside CustomTreeNodeHandler.OnBeforeInsert the GUID is not valid.

Inside CustomTreeNodeHandler.OnAfterInsert there is a NodeGUID but using it to extract AttachmentInfo returns a null. In any case, using FileAttachment returns a null or an empty GUID.

This code is executed inside CustomTreeNodeHandler.OnAfterInsert when the SAVE button is clicked.


Guid nodeguid = (Guid)node.GetValue( "FileAttachment", Guid.Empty );//always empty

if ( nodeguid != Guid.Empty )
{
AttachmentInfo fileinfo = CMS.WorkflowEngine.DocumentHelper.GetAttachment( nodeguid, treeprov, node.NodeSiteName );

if ( fileinfo != null )
{
string filesize = fileinfo.AttachmentSize.ToString();
string filetype = fileinfo.AttachmentExtension;
}
}


Here is the node contents handed in by the event.


node	{CMS.TreeEngine.TreeNode}	CMS.TreeEngine.TreeNode
ColumnNames {string[88]} string[]
CoupledClassIDColumn FileID string
DataRow {System.Data.DataRow} System.Data.DataRow
DocumentCampaign string
DocumentCheckedOutVersionHistoryID 0 int
DocumentContent {CMS.TreeEngine.EditableItems} CMS.TreeEngine.EditableItems
DocumentCulture en-US string
DocumentCustomData {CMS.GlobalHelper.CustomData} CMS.GlobalHelper.CustomData
DocumentExtensions string
DocumentID 212345 int
DocumentMenuCaption string
DocumentMenuClass string
DocumentMenuClassHighlighted string
DocumentMenuClassOver string
DocumentMenuItemImage string
DocumentMenuItemImageHighlighted string
DocumentMenuItemImageOver string
DocumentMenuItemInactive FALSE bool
DocumentMenuItemLeftImage string
DocumentMenuItemLeftImageHighlighted string
DocumentMenuItemLeftImageOver string
DocumentMenuItemRightImage string
DocumentMenuItemRightImageHighlighted string
DocumentMenuItemRightImageOver string
DocumentMenuJavascript string
DocumentMenuRedirectUrl string
DocumentMenuStyle string
DocumentMenuStyleHighlighted string
DocumentMenuStyleOver string
DocumentName 250px-Gallo-Roman_4th_century_shield_boss string
DocumentNamePath /Where We Build/Texas/Temple/Waco/Temple/Waco/Killeen/Windmill Farms/Plans/The Columbus/Floorplan/250px-Gallo-Roman_4th_century_shield_boss string
DocumentPageTemplateID 0 int
DocumentPriority 0 int
DocumentPublishFrom {1/1/0001 12:00:00 AM} System.DateTime
DocumentPublishTo {12/31/9999 11:59:59 PM} System.DateTime
DocumentRatings 0 int
DocumentRatingValue 0 double
DocumentStylesheetID -1 int
DocumentTagGroupID 0 int
DocumentTags string
DocumentUrlPath string
DocumentUseCustomExtensions FALSE bool
DocumentUseNamePathForUrlPath FALSE bool
DocumentWildcardRule string
HasChanged TRUE bool
HasSKU FALSE bool
IsArchived FALSE bool
IsCoupled TRUE bool
IsInPublishStep TRUE bool
IsLink FALSE bool
IsPublished TRUE bool
IsSecuredNode -1 int
mClassName CMS.File string
mColumnNames {string[88]} string[]
mCoupleClass {CMS.DataEngine.SimpleDataClass} CMS.DataEngine.IDataClass {CMS.DataEngine.SimpleDataClass}
mDataRow {System.Data.DataRow} System.Data.DataRow
mDocumentClass {CMS.DataEngine.SimpleDataClass} CMS.DataEngine.IDataClass {CMS.DataEngine.SimpleDataClass}
mDocumentContent {CMS.TreeEngine.EditableItems} CMS.TreeEngine.EditableItems
mDocumentCustomData {CMS.GlobalHelper.CustomData} CMS.GlobalHelper.CustomData
mNodeCustomData {CMS.GlobalHelper.CustomData} CMS.GlobalHelper.CustomData
mOriginalDocumentExtensions string
mOriginalDocumentName 250px-Gallo-Roman_4th_century_shield_boss string
mOriginalDocumentTags string
mOriginalDocumentTagsGroup 0 int
mOriginalDocumentUrlPath string
mOriginalNodeAlias 250px-Gallo-Roman_4th_century_shield_boss-(2) string
mOriginalNodeAliasPath /Where-We-Build/Texas/Temple-Waco-Killeen/Temple-Waco-Killeen/Windmill-Farms/Plans/Columbus/Floorplan/250px-Gallo-Roman_4th_century_shield_boss-(2) string
mOriginalNodeLevel 9 int
mOriginalNodeName 250px-Gallo-Roman_4th_century_shield_boss (2) string
mOriginalNodeParentID 108029 int
mOriginalNodeSKUID 0 int
mOriginalSiteID 2 int
mOriginalValuesLoaded TRUE bool
mSKUClass null CMS.DataEngine.IDataClass
mTreeClass {CMS.DataEngine.SimpleDataClass} CMS.DataEngine.IDataClass {CMS.DataEngine.SimpleDataClass}
mTreeProvider {CMS.TreeEngine.TreeProvider} CMS.TreeEngine.TreeProvider
mWorkflowStepName string
NodeAlias 250px-Gallo-Roman_4th_century_shield_boss-(2) string
NodeAliasPath /Where-We-Build/Texas/Temple-Waco-Killeen/Temple-Waco-Killeen/Windmill-Farms/Plans/Columbus/Floorplan/250px-Gallo-Roman_4th_century_shield_boss-(2) string
NodeBodyElementAttributes string
NodeCacheMinutes -1 int
NodeChildNodesCount 0 int
NodeClassName CMS.File string
NodeCustomData {CMS.GlobalHelper.CustomData} CMS.GlobalHelper.CustomData
NodeDocType string
NodeGUID {caa3242d-73d0-4265-b841-5784c44787a2} System.Guid
NodeHeadTags string
NodeID 189045 int
NodeInheritPageLevels string
NodeLevel 9 int
NodeName 250px-Gallo-Roman_4th_century_shield_boss (2) string
NodeOrder 3 int
NodeOwner 6756 int
NodeParentID 108029 int
NodeSiteID 2 int
NodeSiteName DRHorton string
NodeSKUID 0 int
OriginalNodeID 189045 int
PublishedVersionExists TRUE bool
RequiresSSL -1 int
SearchType cms.document string
TreeProvider {CMS.TreeEngine.TreeProvider} CMS.TreeEngine.TreeProvider
WorkflowStepName string
Static members


There is no FileAttachment entry there.

Thanks.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 8/25/2012 9:32:26 PM
   
RE:CMS.CustomEventHandler.CustomDataHandler
Hi,

I tested behavior with blog post document type (the attachment field is using direct uploader form control) and the guid was available in on before insert event handler.

This control uploads the image before the document is saved, i.e. code:

object guid = node.GetValue("BlogPostTeaser");

returns not empty value. It behaves the same way as for example title field.

Could you please double check if name of your column is correct?

P.S. Here is code which works in version 6.0:


using CMS.TreeEngine;
using CMS.SettingsProvider;

[CustomDocumentEventsTest]
public partial class CMSModuleLoader
{
/// <summary>
/// Attribute class that ensures the loading of custom handlers
/// </summary>
private class CustomDocumentEventsTest : CMSLoaderAttribute
{
/// <summary>
/// Called automatically when the application starts
/// </summary>
public override void Init()
{
DocumentEvents.Insert.Before += new System.EventHandler<DocumentEventArgs>(Insert_Before);

}

private void Insert_Before(object sender, DocumentEventArgs e)
{
if (e.Node.NodeClassName.ToLower() == "cms.blogpost")
{
object guid = e.Node.GetValue("BlogPostTeaser");
}
}

}


Best regards,
Ivana Tomanickova

User avatar
Member
Member
enelson-drhorton - 8/27/2012 10:03:41 AM
   
RE:CMS.CustomEventHandler.CustomDataHandler
Your post does not make much sense in response to my post.

Please review my post of '8/22/2012 1:42:10 PM'. I am showing the code being used. I am looking for 'FileAttachment' as was recommended by your post of ' 8/21/2012 4:32:24 PM'. It did not work. I am showing why by detailing the contents of the node in my post. 'FileAttachment' is not present. Trying to reference the GUID directly will NOT return 'AttachmentInfo' data.

Here is a recap.

Using CMS.CustomEventHandler.CustomDataHandler results in the parent node not being available. The AttachmentInfo is present. If I could find the parent node data, I could do my work. You recommended going to TreeNodeHandler. Ok - lets look there.

Inside TreeNodeHandler, the CMS.File node being passed in as per my post of '8/22/2012 1:42:10 PM' and it does not have the file information available, either by accessing the 'FileAttachment' data - which I have show is not present - or by the GUID.

Lastly, I stated in my post of '8/9/2012 3:54:05 PM', I stated that I am using 5.5. Doing tests on 6.0 are a waste of time.

I need another option. Something that works with attached images in the tree node, not blog posts.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 8/30/2012 7:33:56 PM
   
RE:CMS.CustomEventHandler.CustomDataHandler
Hi,

here is a working code for R2 version:


public override void OnBeforeUpdate(object treeNodeObj, object tree)
{
TreeProvider newTree = (TreeProvider)tree;
TreeNode newDoc = (TreeNode)treeNodeObj;


// handle the event only for press release items
if (newDoc.NodeClassName.ToLower() == "cms.file")
{
Guid imageGuid = ValidationHelper.GetGuid(newDoc.GetValue("FileAttachment"), Guid.Empty);

CMS.FileManager.AttachmentInfo ai = DocumentHelper.GetAttachment(imageGuid, newTree, "CorporateSite");
}
}


This method is called when file document is inserted or updated.

Best regards,
Ivana Tomnaickova