Copied to clipboard

Flag this post as spam?

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


  • Phillip Ng 148 posts 250 karma points
    Jun 17, 2014 @ 23:27
    Phillip Ng
    0

    Need to Get Media File Name

    Hello

    In a class, I have something like CoverImage = cms.GetMediaFileUrl(node.GetPropertyString("coverImage")). Then in my macro:

    var articles = currentNode.ChildrenAsList.Select(ModelHelper.PrepareArticleModel).ToList();
    @foreach (var article in articles.Skip((page - 1) * pageSize).Take(pageSize)) {
    if ( article.CoverImage != "" ) {
    <div class="blog-img-pad">
    <img src="@(article.CoverImage)" border="0" alt="">
    </div>
    }
    }

    Currently, I'm missing a way to get to the name of the CoverImage. What method should I be invoking to gain access to it? It's probably something really simple that I'm totally blanking on... thanks in advance for any assistance!

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 17, 2014 @ 23:49
    Dennis Aaen
    0

    Hi Phillip,

    I would try to help you, I assume that you get the src to the image out by using this:

    <img src="@article.CoverImage" border="0" alt="">

    Have you tried something like this to get the name of the file?

    var articles = currentNode.ChildrenAsList.Select(ModelHelper.PrepareArticleModel).ToList();

    @foreach (var article in articles.Skip((page - 1) * pageSize).Take(pageSize)) {
        if (article.CoverImage != "" ){
            <div class="blog-img-pad">
                <img src="@article.CoverImage" border="0" alt="@article.CoverImage.Name">
            </div>

        }
    }

    Hope this gives you the filename.

    /Dennis

  • Phillip Ng 148 posts 250 karma points
    Jun 18, 2014 @ 00:10
    Phillip Ng
    0

    Hi Dennis

    Thanks for the assistance. Unfortunately, I get an error saying, "'string' does not contain a definition for 'Name' and no extension method 'Name' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?"

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 18, 2014 @ 00:16
    Dennis Aaen
    0

    Okay Phillip,

    Does this give you anything in the alt attribute.

    var articles = currentNode.ChildrenAsList.Select(ModelHelper.PrepareArticleModel).ToList();

    @foreach(var article in articles.Skip((page -1)* pageSize).Take(pageSize)){
       
    if(article.CoverImage!=""){
           
    <div class="blog-img-pad">
               
    <img src="@article.CoverImage" border="0" alt="@article.Name" />
            </
    div>

       
    }
    }

    /Dennis

  • Phillip Ng 148 posts 250 karma points
    Jun 18, 2014 @ 02:56
    Phillip Ng
    0

    No, article.Name doesn't work either.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies