Simple way to hook into AfterPublish event using Custom DataType
Hi all, hope we're doing ok on this "lovely" Monday morning!
I'm wondering if theres an easy method to hook an existing custom datatype I've written in to a documents AfterPublish event?
I've seen a couple of articles on this, and looking at them it would seem as though I'd have to rewrite the datatype more or less completly. I'm not totally against this, but if theres an easier way I'd much rather do that! :-)
If you only want it on the page(s) which the Data Type is being used on you could put it into the ctor of the Data Type. But you'll need to make sure you don't register the event multiple times if the data type is used multiple times.
You're really best to use ApplicationBase and register it that way, this will ensure that it's only registering the event handler once and regardless of whether the Data Type is being used.
Why do you want to insert a datatype when a document is published? I think you should either create a new datatype (which is not that painfull) or insert a value when publishing. Maybe I'm just not understanding what you are trying to achieve?
Crossed wires I think. Basically I've written a datatype which generates the TinyUrl for the document/page. At the moment it generates the value when a button is clicked, and will only generate the value when the page is published (therefore can access node.Url).
Whilst this is possibly not a terrible method, I'd like to be able to automatically generate the TinyUrl value when the page is initally published. For subsequent times there would be a 'Regenerate' button which would request a new url for if the node name was changed for example.
Slace,
Can you give me an example what how I would register the event in the constructor? As the examples I've seen are Class Libraries that inherit solely off ApplicationBase rather than UserControls
I'm still confused as to why you're using a datatype for this? I'd rather build an event handler hooking into the save/publish of a document and update a document's property accordingly? It can be a property of type 'Label' to make sure editors cannot modify the contents.
Simple way to hook into AfterPublish event using Custom DataType
Hi all, hope we're doing ok on this "lovely" Monday morning!
I'm wondering if theres an easy method to hook an existing custom datatype I've written in to a documents AfterPublish event?
I've seen a couple of articles on this, and looking at them it would seem as though I'd have to rewrite the datatype more or less completly. I'm not totally against this, but if theres an easier way I'd much rather do that! :-)
Thanks all
If you only want it on the page(s) which the Data Type is being used on you could put it into the ctor of the Data Type. But you'll need to make sure you don't register the event multiple times if the data type is used multiple times.
You're really best to use ApplicationBase and register it that way, this will ensure that it's only registering the event handler once and regardless of whether the Data Type is being used.
Hi,
Why do you want to insert a datatype when a document is published? I think you should either create a new datatype (which is not that painfull) or insert a value when publishing. Maybe I'm just not understanding what you are trying to achieve?
Cheers,
Richard
Richard,
Crossed wires I think. Basically I've written a datatype which generates the TinyUrl for the document/page. At the moment it generates the value when a button is clicked, and will only generate the value when the page is published (therefore can access node.Url).
Whilst this is possibly not a terrible method, I'd like to be able to automatically generate the TinyUrl value when the page is initally published. For subsequent times there would be a 'Regenerate' button which would request a new url for if the node name was changed for example.
Slace,
Can you give me an example what how I would register the event in the constructor? As the examples I've seen are Class Libraries that inherit solely off ApplicationBase rather than UserControls
elspiko,
I'm still confused as to why you're using a datatype for this? I'd rather build an event handler hooking into the save/publish of a document and update a document's property accordingly? It can be a property of type 'Label' to make sure editors cannot modify the contents.
Here's a starter that may inspire...
Hope this helps.
Regards,
/Dirk
is working on a reply...