I am trying to create an EventHandler which checks to see if my custom officialPublicationDate field has been filled in and if not places the current datetime into it. Trouble is it does not seem to be firing! Code is below:
using System; using System.Collections.Generic; using System.Text; using umbraco.BusinessLogic; using umbraco.cms.businesslogic.web;
namespace AddStoryDate { public class CheckDate :ApplicationBase { public CheckDate() { Document.BeforePublish += new Document.PublishEventHandler(Document_BeforePublish); }
I have tried it using both BeforeSave and BeforePublish but as far as I can see it is not firing or (quite likely) the code is not coorect to check or set my field.
Any help would be greatly appreciated. This is my first foray into extending Umbraco.
Turns out that the event I was thinking about is BeforeDelete.
Hope that someone who has more knowledge of the umbraco events can help you out. Because for all that I know the code seems to be fine so I'm also curious about the solution for this.
Although you've probably uploaded a new dll (holding the code for the event) to the /bin folder, it's probably still not registered... I'd recommend to either touch the web.config or to restart the application to force umbraco to reload all event handlers!
Try to set a debug statement on the constructor and attach the debugger so you can see if the Event will be wired up. If that is the case set a breakpoint on the first line of the Document_BeforePublish event handler and attach the debugger again and then step through the code to see what is wrong.
- DocumentType.BeforeSave is fired AFTER Property changes are saved -
setting a different template (if multiple templates available for
current doc type) will get persisted even if you're cancelling out the
event! - text, update date, release date, expire date are also persisted to the database before being able to cancel out the event.
BeforePublish EventHandler
I am trying to create an EventHandler which checks to see if my custom officialPublicationDate field has been filled in and if not places the current datetime into it. Trouble is it does not seem to be firing! Code is below:
I have tried it using both BeforeSave and BeforePublish but as far as I can see it is not firing or (quite likely) the code is not coorect to check or set my field.
Any help would be greatly appreciated. This is my first foray into extending Umbraco.
Cheers in advance
Paul.
Hi Paul
What version of Umbraco are you trying to do this in?
I think I have read somewhere that the Beforepublish event does'nt work before v4.1 is released.
/Jan
Turns out that the event I was thinking about is BeforeDelete.
Hope that someone who has more knowledge of the umbraco events can help you out. Because for all that I know the code seems to be fine so I'm also curious about the solution for this.
/Jan
If it helps it is v4.0.1
Although you've probably uploaded a new dll (holding the code for the event) to the /bin folder, it's probably still not registered... I'd recommend to either touch the web.config or to restart the application to force umbraco to reload all event handlers!
Cheers,
/Dirk
I did touch the web.config after I copied the dll.
Hi,
Try to set a debug statement on the constructor and attach the debugger so you can see if the Event will be wired up. If that is the case set a breakpoint on the first line of the Document_BeforePublish event handler and attach the debugger again and then step through the code to see what is wrong.
Hope this helps you,
Richard
Edit function would be cool, debug statement must be a breakpoint....
Check this issue on umbraco codeplex:
http://umbraco.codeplex.com/WorkItem/View.aspx?WorkItemId=21847
«
- DocumentType.BeforeSave is fired AFTER Property changes are saved
- setting a different template (if multiple templates available for current doc type) will get persisted even if you're cancelling out the event!
- text, update date, release date, expire date are also persisted to the database before being able to cancel out the event.
»
is working on a reply...