Copied to clipboard

Flag this post as spam?

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


  • Amigo 243 posts 568 karma points
    Sep 16, 2010 @ 16:22
    Amigo
    0

    set the "Publish at" automatic

    Is it possible to set the "Publish at" automatic to the same as "created date" when a new page is created?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 16, 2010 @ 16:30
    Dirk De Grave
    0

    why would you do that? you can publish document immediately after having created it

    document.Publish(user u);
    umbraco.library.UpdateDocumentCache(document.Id);

     

    Cheers,

    /Dirk

  • Amigo 243 posts 568 karma points
    Sep 16, 2010 @ 17:08
    Amigo
    0

    i  want to do that because i need a second dato om make a sort on that overrules created date...
    so i was hoping i could fit umbraco to do i by default when creating a site (wich is a teaser....)

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 16, 2010 @ 17:16
    Dirk De Grave
    0

    ...well, makes more sense, but then I still wouldn't use the publish date for that, I'd add another date field on document type(s) and write a simple event handler that'll fill in that field for you.

    Details on how to build an event handler can be found in the wiki starting here.

     

    Cheers,

    /Dirk

  • Amigo 243 posts 568 karma points
    Sep 28, 2010 @ 15:37
    Amigo
    0

    Hi Dirk,

    Finally i have time to respond now. Sorry for waiting.

    Im brand new to Umbraco, so here is maybe a couple of stupid questions....

    I have created a new "sortdate" date field on the "properties" tap.

    1/
    When writing a event handler class, does it have to be located a specific place in the solution?

    2/
    The new field value must only be set once when publishing the page the first time, how do i do that?

  • Amigo 243 posts 568 karma points
    Sep 28, 2010 @ 16:04
    Amigo
    0

    Ok, i created my handler in the app_code directory...
    And im thinking to use the "Document_AfterNew"....
    But how will i fetch my new "sortdate" date field so i can set datetime.now into it?

  • Amigo 243 posts 568 karma points
    Sep 28, 2010 @ 17:04
    Amigo
    0

    Ok, i think i got it, used the "beforepublish" instead because "afternew" did not have ref to the current document.
    Thanks for helping ;-)

    Here is my code:
    public class SetBlogSortDate : umbraco.BusinessLogic.ApplicationBase
    {
      public SetBlogSortDae(
      {
       
       Document.BeforePublish += new Document.PublishEventHandler(Document_BeforePublish);
      }

     

     

      void Document_BeforePublish(Document sender, PublishEventArgs e)

       {
         

     

    if(sender.Template == 1185 && sender.getProperty("sortDate").Value == string.Empty)
       {
            sender.getProperty("sortDate").Value = DateTime.Now;
       }
      }
    }

Please Sign in or register to post replies

Write your reply to:

Draft