Copied to clipboard

Flag this post as spam?

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


  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jan 11, 2011 @ 16:52
    Bo Damgaard Mortensen
    0

    C# Publish At

    Hi all,

    I'm trying to build a simple page for adding news documents to my site from my mobile. I would like to be able to pick a date (from an asp calendar control) for when the news document should be published. I've been fooling around with the ReleaseDate property on the Document class, but oddly enough it returns the date: 01-01-0001 even if I set the publish at date in Umbraco to 15-01-2011 for example.

    Has anyone got any experience with this? :)

    Any help or hint is greatly appreciated!

    Thanks in advance,

    Bo

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Jan 11, 2011 @ 16:56
    Richard Soeteman
    0

    Hi Bo,

    Think you need to format your date to 01/15/2011. Umbraco is quite strict about that.

    Cheers,

    Richard

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jan 11, 2011 @ 17:12
    Bo Damgaard Mortensen
    0

    Hi Richard, thanks for your reply! :)

    Good point about the datetime format there! However, i just tried the following code:

    myTextBox.Text = doc.ReleaseDate.ToString();

    And it shows: "01-01-0001 00:00:00" in the TextBox aswell (?)

    Isn't RelaseDate the same as "Publish At" in Umbraco, or?

     

    Thanks again!

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jan 11, 2011 @ 17:18
    Bo Damgaard Mortensen
    0

    .. and it's the exact same with Expire Date / Unpublish at.. Have I missed something here? :/

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Jan 11, 2011 @ 17:22
    Richard Soeteman
    0

    Yep Releasedate is the property.. Think I was wrong in my first answer. I did an import myself which is basically doing the same as you are doing and data is stored as 2011-06-30 00:00 so the format is  year-month-day

    I've seen more issues with date.ToString().

    Cheers,

    Richard

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jan 11, 2011 @ 17:53
    Bo Damgaard Mortensen
    0

    Ahh, you're right! The date is actually displayed as year-month-day in Umbraco! /facepalm.

    Hmm, but shouldn't:

    doc.ReleaseDate.ToString();

    output: 01-19-2011 00:00 instead of 01-01-0001 00:00:00 then? Or does it output  01-01-0001 00:00:00 because the date time format is wrong?

    I feel quite lost when it comes to formatting datetime in C# to be honest :( With the risk of sounding helpless: do you have an example/hint as how to format the date to correspond the date in Umbraco?

    Thanks again!

    Bo

     

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Jan 12, 2011 @ 09:50
    Richard Soeteman
    0

    Hi Bo,

    The releasedate .ToString outputs correct but Umbraco doesn't understand it. In CMSImport (which I took a look at) I just assign the database value which was stored as '2011-06-30 00:00:00.000'

    If you want to add a formatten to the ToString method you shoudl take a look at http://idunno.org/archive/2004/07/14/122.aspx Best article on this subject. From the top of my head you should use doc.ReleaseDate.ToString("yyyy-MM-dd");.

    Hope this helps you,

    Richard 

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jan 12, 2011 @ 16:08
    Bo Damgaard Mortensen
    0

    Hi Richard,

    Thanks again for your response :) It's greatly appreciated!

    I just got the chance to take a look at this problem again now and I tried the doc.ReleaseDate.ToString("yyyy-MM-dd"); which returns "0001-01-01". I then found the document in the database and the date is correctly set to 2011-02-10 08:08:00 as I set in Umbraco.

    .. what's the deal?

    This is my code in question:

    protected void Selection_Changed(Object sender, EventArgs e)
        {
            foreach (Document doc in unpublishedNews)
            {
                if (doc.Text.Equals(ddNews.SelectedItem.Value))
                {
                    txtIndhold.Text = doc.getProperty("bodyText").Value.ToString();
                    string dt = doc.ReleaseDate.ToString("yyyy-MM-dd");                
                    txtOverskrift.Text = dt;
                }
            }
        }

    the asp control I'm using is a DropDownList control.. So this code fires when the selection has changed. I think it's safe to say that I'm totally confused about this ;)

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jan 12, 2011 @ 16:18
    Bo Damgaard Mortensen
    0

    O.k I figured it out! However, the solution is quite weird to me.

    In my Selection_Changed event I have to new up a new document in the foreach loop with the id of the current document like this:

        protected void Selection_Changed(Object sender, EventArgs e)
        {
            foreach (Document doc in unpublishedNews)
            {
                if (doc.Text.Equals(ddNews.SelectedItem.Value))
                {
                    Document document = new Document(doc.Id);
                    txtIndhold.Text = document.getProperty("bodyText").Value.ToString();               
                    string dt = document.ReleaseDate.ToString("yyyy-MM-dd");
                    txtOverskrift.Text = dt;
                }
            }
        }

    Then it outputs the correct ReleaseDate and ExpireDate. 

    My only question is... why? It can display all the other data such as bodyText and header etc, but can't display the releasedate and exp.date if it's not a new document?

    Can anyone clarify this?

     

Please Sign in or register to post replies

Write your reply to:

Draft