Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    May 23, 2013 @ 15:41
    Fuji Kusaka
    0

    IsFirst or IsPosition in Media

    Hi Guys,

    How do i get the First Value in a Media Folder using GetChildMedia()

    Media StartMedia = new Media(@Id);
    foreach(Media p in StartMedia.GetChildMedia()){
    @p.getProperty("umbracoFile").Value <br/> if(p.IsFirst()){ } @StartMedia.Children.First().getProperty("umbracoFile").Value
    }

    Here am getting an error when saving the file

    error CS1061: 'umbraco.cms.businesslogic.media.Media' does not contain a definition for 'IsFirst

     

  • Fuji Kusaka 2203 posts 4220 karma points
    May 23, 2013 @ 20:06
    Fuji Kusaka
    0

    Any thoughts on this  ?

  • Joe Morrison 20 posts 80 karma points
    May 24, 2013 @ 09:41
    Joe Morrison
    0

    before the for each :

     

    var count = 0;

     

    then in the foreach 

    count++;
    if(count = 1){
    @*I am the first - grab my value here *@
    }
  • Fuji Kusaka 2203 posts 4220 karma points
    May 24, 2013 @ 10:10
    Fuji Kusaka
    100

    Hi Joe, 

    Thanks for the response. 

    I somehow did it in another way. I checked if the first media in the loop matches the id

     

    var firstImg = StartMedia.Children.First().Id; 
        if(f.Id == @firstImg){
              @StartMedia.Children.First().Id <br/>
          }
         else{
              @f.Text<br/>
          }

     

  • Joe Morrison 20 posts 80 karma points
    May 24, 2013 @ 10:16
    Joe Morrison
    0

    No worries - that seems more efficient than my method, which adds an extra variable and increments it in the loop to grab just one item - will note your method for future!

     

    Joe

  • Stephen 767 posts 2273 karma points c-trib
    Jun 04, 2013 @ 11:25
    Stephen
    0

    FWIW at the moment the IsFirst(), IsLast() etc methods and properties are somewhat buggy in 6.1 and previous versions. Current working on fixing them, hopefully sometime after CG13 we'll have clean methods.

  • Fuji Kusaka 2203 posts 4220 karma points
    Jun 04, 2013 @ 11:27
    Fuji Kusaka
    0

    Hi Stephen,

    Thanks for pointing this out .

Please Sign in or register to post replies

Write your reply to:

Draft