Copied to clipboard

Flag this post as spam?

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


  • John Davis 4 posts 22 karma points
    Oct 05, 2011 @ 20:24
    John Davis
    0

    Getting updateDate of Media object

    Hi All,

     

    I need to get the Update Date of a media object and have not been able to do so, I have the following code that loops thru a media folder and works but I need the updateDate for each media item.

     

    Thanks in advance for your help!

    John

    @using umbraco.cms.businesslogic.media;
    @using uComponents.Core;
    @using uComponents.Core.uQueryExtensions;
    @using System
    @{
      // Set default media root node id
      int rootNodeId = 1116;
    
      // Try to get media id from macro parameter "mediaFolderNodeId" type "mediacurrent"
      Int32.TryParse(Parameter.source, out rootNodeId);
    
      // Try to get media id from querystring
      if (Request["OpenMediaFolderId"]!=null)
      {
        Int32.TryParse(Request["OpenMediaFolderId"], out rootNodeId);
      }
    
      // Get media node and iterate the children
      var m = new Media(rootNodeId);
    
    <table class="info-table">
    <tr><th>Toolkit:</th><th>Updated On:</th>
    
      @foreach (var c in m.GetChildMedia())
      {
       if( c.GetPropertyAsString("Category") == @Parameter.category ) {
       <tr>
          <td><a href="@c.GetPropertyAsString("Filename")">@c.GetPropertyAsString("Description")</a></td>
        </tr>
       }
      }
      </table>
    }
  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Oct 05, 2011 @ 22:32
    Dan Diplo
    0

    Your using Razor syntax but you're not really using any of the new dynamic node classes that were introduced with Razor that make dealing with this kind of thing easier. Presuming you are using Umbraco 4.7.1 then you can do this to get a quick list of items in a media folder and their Update Date:

       dynamic folder = Library.MediaById(1234);
    
        if (folder.NodeTypeAlias == "Folder")
        {
           <ul>
            @foreach (var media in folder.Children)
            {
                <li>
                    @media.Name - @media.UpdateDate
                </li>
            }
           </ul>
        }

    Using dynamic types make it much cleaner and you need less code. I'm sure you can adapt this to your needs.

  • John Davis 4 posts 22 karma points
    Oct 06, 2011 @ 15:51
    John Davis
    0

    Dan,

    Thanks so much, that did it. Time for me to read up on the Dynamic Node stuff. Adios XSLT!

     

    John

Please Sign in or register to post replies

Write your reply to:

Draft