Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Paul Hulatt 47 posts 59 karma points
    Sep 05, 2009 @ 12:39
    Paul Hulatt
    0

    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:

    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);
            }
            void Document_BeforePublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)
            {
                Log.Add(LogTypes.Custom, sender.Id, "Event Raised");
                if (sender.ContentType.Alias == "News Item")
                {
                    if (sender.getProperty("officialPublicationDate").Value.Equals(DateTime.MinValue))
                    {
                        sender.getProperty("officialPublicationDate").Value = DateTime.Now;
                        sender.Save();
                    }
                }
            }
        }
    }

    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.

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Sep 05, 2009 @ 12:54
    Jan Skovgaard
    0

    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

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Sep 05, 2009 @ 13:01
    Jan Skovgaard
    0

    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

  • Paul Hulatt 47 posts 59 karma points
    Sep 05, 2009 @ 13:17
    Paul Hulatt
    0

    If it helps it is v4.0.1

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 05, 2009 @ 13:31
    Dirk De Grave
    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

  • Paul Hulatt 47 posts 59 karma points
    Sep 05, 2009 @ 21:44
    Paul Hulatt
    0

    I did touch the web.config after I copied the dll.

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Sep 06, 2009 @ 10:52
    Richard Soeteman
    0

    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

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Sep 06, 2009 @ 10:53
    Richard Soeteman
    0

    Edit function would be cool, debug statement must be a breakpoint....

  • pvassalo 21 posts 28 karma points
    Sep 09, 2009 @ 13:04
    pvassalo
    0

    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.

    »

     

Please Sign in or register to post replies

Write your reply to:

Draft