Copied to clipboard

Flag this post as spam?

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


  • Richard Thompson 100 posts 336 karma points
    Mar 17, 2015 @ 14:16
    Richard Thompson
    0

    Empty CreateDateTime in a Macro Script

    Hi,

    I've got an Umbraco 4.11.10 site which has a razor script to list out some documents from a particular media folder.  It outputs the umbracoFile, name and umbracoBytes for every file correctly but the CreateDateTime is empty for every document.  UpdateDate shows the last modified date but obviously this isn't the date I need.

    Does anybody have any ideas or is there another way I can get the created date for each media item?

    Here is my script:

    DynamicMedia folder = new DynamicMedia(mediaFolderId);
        if (folder != null && folder.Children.Items.Count() > 0)
        {
    int results = folder.Children.Items.Count();
    int totalPages = ( ( results + ( results % pageSize ) ) / pageSize );
    int i = 0;
    <p>@results results, page @page of @totalPages</p>
            <table>
             <tr>
               <th>Type</th>
               <th>Title</th>
               <th>Size</th>
               <th>Date Added</th>
             </tr>
                @foreach( dynamic media in folder.Children.Items )
                {
    if( i >= ( ( page - 1 ) * pageSize ) && i < page * pageSize )
    {  
    double sizeInBytes = 0;
    try
    {
    sizeInBytes = Convert.ToDouble( @media.umbracoBytes );
    }
    catch( FormatException ){}
    string size = sizeInBytes + " Bytes";
    if( sizeInBytes > 1024 * 1024 )
    {
    size = ( sizeInBytes / 1024d /1024d ).ToString( "N2" ) + " MB";
    }
    else if( sizeInBytes > 1024 )
    {
    size = ( sizeInBytes / 1024d ).ToString( "N2" ) + " KB";
    }
    <tr>
      <td><img src="/media/10285/pdficon.gif" alt="pdf" /></td>
      <td><a href="@media.umbracoFile" target="_blank">@media.Name</a></td>
      <td>@size</td>
      <td>@media.CreateDateTime</td>
    </tr>

    }
    i++;
                }
  • Dan Lister 416 posts 1974 karma points c-trib
    Mar 18, 2015 @ 09:49
    Dan Lister
    0

    Hi RIchard,

    I don't think a DynamicMedia instance contains a property called CreateDateTime. I've checked Umbraco's source and there is one called CreateDate. Could you try using that?

    I hope that helps.

    Thanks, Dan.

  • Richard Thompson 100 posts 336 karma points
    Mar 18, 2015 @ 10:11
    Richard Thompson
    0

    Hi Dan,

    Thanks for the help.  I tried CreateDate but everything came out as 1/1/0001 12:00:00 AM.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 18, 2015 @ 18:56
    Dennis Aaen
    0

    Hi Richard,

    What if you do something like this would you then get the date outputted in the right format.

    <td>@media.CreateDate.ToString("dd-MM-yyyy")</td>

    Here are some documentation on the different parameters https://our.umbraco.org/wiki/reference/umbracolibrary/formatdatetime

    Hope this helps,

    /Dennis

  • Richard Thompson 100 posts 336 karma points
    Mar 19, 2015 @ 13:43
    Richard Thompson
    0

    Hi Dennis,

    Thanks for the help.  I've tried that code but the dates all come out as 01-01-0001.  It's like the creation date is always empty although there is one in the back office.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 19, 2015 @ 13:56
    Dennis Aaen
    0

    Hi Richard,

    Perhaps it helps, if you re-build the Examine indexes. You will find on the examine indexes, if you go to the developer section, in the right top of the dashbord, in a tab called examine management.

    Hope this can help you get the right date back on your images.

    /Dennis

  • Richard Thompson 100 posts 336 karma points
    Mar 23, 2015 @ 17:31
    Richard Thompson
    0

    Hi,

    I didn't have that option available so I installed Examine Dashboard and rebuilt the indexes but unfortunately that has made no difference.

Please Sign in or register to post replies

Write your reply to:

Draft