How to use event handlers on custom document types?
I must completly have missed something. It might be that I'm new to both Umbraco and .net, but I can't seem to figure out how use the event handlers on custom document types. Actually the problem is that I can't figure out how to implement and use the custom document types in Umbraco in the first place. Maybe I have got it all wrong?!
Can anyone please point me in the right direction, or maybe just in the direction of where to find the documentation for it (if any)?
Cheers, Dan
Ps. : This is probably one of those post that has such a simple solution
that I end up being embarred about ever posting it, so please be gentle
;-)
If you want to react on the publishing of a content item from a special document type just implement the BeforePublish event handler and check for the document type alias of the document which will be saved.
I think you might have misunderstood my problem. I have read the
examples but don't get how they will end up working in my umbraco
application. My "issue" is probably a much more fundamental one.
Making a class with the functions that handles the
event - no problem. Compiling it to a dll - no problem. Uploading the
dll to the Umbraco installation dir/bin - no problem. Where to go from
there - big problem ;-)
As mentioned before, I might have got the Idea of how it works all wrong.
Oh, so I misunderstood you. So let me have another try:
As I understand right you have implemented an event handler which is doing something on publishing a document?
If so and you have uploaded the dll to the bin folder the umbraco installation will automatically reinitialize (it is a .Net feature that if you change something in the bin folder rthe app reinitializes). Umbraco then will go throught the included dlls via .NET reflection and will search for all event handlers and registers them. So if you have uploaded an event handlers dll it will work automatically.
Could I help you with that or do you have another problem?
I'm playing around with similar stuff, but instead of checking for a particular DocumentType, I need to know if my custom DataType is being used in the DocumentType of the current Document. If so, I need to write some XML to the file system based on the value of the respective Property.
Any pointers on how I'd find only my custom DataType? Is there a more elegant way than iterating through like this?
private void Document_AfterPublish(Document sender, EventArgs e) { foreach (Property DOCPROP in sender.getProperties) { if (DOCPROP.PropertyType.DataTypeDefinition.DataType is MY.DATA.TYPE) { // TODO: Write XML to file system } } }
var properties = sender.getProperties;
var datatypes = from p in properties where p.PropertyType.DataTypeDefinition.DataType.Id.ToString() == myDataType.Id.ToString());
if (datatypes.Length == 1) { // datatype found }
How to use event handlers on custom document types?
I must completly have missed something. It might be that I'm new to both Umbraco and .net, but I can't seem to figure out how use the event handlers on custom document types. Actually the problem is that I can't figure out how to implement and use the custom document types in Umbraco in the first place. Maybe I have got it all wrong?!
Can anyone please point me in the right direction, or maybe just in the direction of where to find the documentation for it (if any)?
Cheers,
Dan
Ps. : This is probably one of those post that has such a simple solution that I end up being embarred about ever posting it, so please be gentle ;-)
First take a list on the available event handlers: http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events/overview-of-all-events
If you want to react on the publishing of a content item from a special document type just implement the BeforePublish event handler and check for the document type alias of the document which will be saved.
hth, Thomas
Forgot the link to the example: http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events/event-examples
Thomas
I think you might have misunderstood my problem. I have read the examples but don't get how they will end up working in my umbraco application. My "issue" is probably a much more fundamental one.
Making a class with the functions that handles the event - no problem. Compiling it to a dll - no problem. Uploading the dll to the Umbraco installation dir/bin - no problem. Where to go from there - big problem ;-)
As mentioned before, I might have got the Idea of how it works all wrong.
/Dan
Oh, so I misunderstood you. So let me have another try:
As I understand right you have implemented an event handler which is doing something on publishing a document?
If so and you have uploaded the dll to the bin folder the umbraco installation will automatically reinitialize (it is a .Net feature that if you change something in the bin folder rthe app reinitializes). Umbraco then will go throught the included dlls via .NET reflection and will search for all event handlers and registers them. So if you have uploaded an event handlers dll it will work automatically.
Could I help you with that or do you have another problem?
Thomas
You nailed it Thomas.
But won't the publish event be executed no matter what document type is published? If so, I guess the trick is to check for the document type?
/Dan
You are right, but you can check the document type alias of the document which you want to react to:
In the if statement you are doing the tasks you only wnat to do for this document type
If you want to cancel the whole publishing process of this node you can add e.Cancel = true;
hth, Thomas
Thank you for your help Thomas. I will try that.
Cheers
/Dan
I'm playing around with similar stuff, but instead of checking for a particular DocumentType, I need to know if my custom DataType is being used in the DocumentType of the current Document. If so, I need to write some XML to the file system based on the value of the respective Property.
Any pointers on how I'd find only my custom DataType? Is there a more elegant way than iterating through like this?
private void Document_AfterPublish(Document sender, EventArgs e)
{
foreach (Property DOCPROP in sender.getProperties)
{
if (DOCPROP.PropertyType.DataTypeDefinition.DataType is MY.DATA.TYPE)
{
// TODO: Write XML to file system
}
}
}
Hi,
Me thinks it can be done using Linq
Hope this helps.
Regards,
/Dirk
Dirk,
Nice timely post will help with http://our.umbraco.org/projects/broken-link-checker/feature-suggestions/8665-Report-no-href-as-broken-link
Regards
Ismail
is working on a reply...