Copied to clipboard

Flag this post as spam?

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


  • Peter Gabriel 2 posts 22 karma points
    Jan 25, 2011 @ 09:24
    Peter Gabriel
    0

    Publish at before publish event causes Object reference not set to instance ...

    public class AppBase : umbraco.BusinessLogic.ApplicationBase {

       
    public AppBase() {
           
    Document.BeforePublish += new Document.PublishEventHandler(Document_BeforePublish);
       
    }

       
    void Document_BeforePublish(Document sender, PublishEventArgs e) {
       
    // This line causes the error on publish at
           Node myParent= new Node(sender.Parent.Id);

       
    }
    }
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 25, 2011 @ 09:40
    Jan Skovgaard
    0

    Hi Peter

    What is it that you're exactly trying to achieve when the event occurs?

    I guess you're probably missing a check or something. But if you could please ellaborate a bit more it would be easier to help you out.

    /Jan

  • Peter Gabriel 2 posts 22 karma points
    Jan 25, 2011 @ 09:50
    Peter Gabriel
    0

    Hey,

    I'm working on code from the Blog4Umbraco project, this specific code creates a year/month/day folder on the beforePublish event. This works perfectly on a normal publish, but gives an "object reference ..." error on a publish at.

    The value of sender.Parent.Id is correct, so you would think retreiving the node would not be a problem.

    Here you can find the code:

    http://blog4umbraco.codeplex.com/SourceControl/changeset/view/61225#983069

    This line causes the error:

    Node topBlogLevel = new Node(sender.Parent.Id);

    Grtz,

    Peter

  • Ben Tice 31 posts 131 karma points
    Jun 06, 2011 @ 17:14
    Ben Tice
    0

    Hi Peter,

    I've had the same issue. I've gotten around it by doing the date folder stuff AfterSave rather than BeforePublish (BlogDateFolder.cs).

    So:

    Document.BeforePublish += new Document.PublishEventHandler(Document_BeforePublish);

    becomes:

    Document.AfterSave += new Document.SaveEventHandler(Document_AfterSave)

    and for the method:

    void Document_AfterSave(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)

    Basically, the datefolders are then created when the document is initially saved. Then, the Publish At functionality works properly. Please note that the changeset I used was from Blog4Umbraco 2.0.26 with the datefolder patch (42029).

    Ben

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies