Copied to clipboard

Flag this post as spam?

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


  • David McGawn 37 posts 150 karma points
    Aug 08, 2016 @ 09:48
    David McGawn
    0

    Monday Morning Brain Freeze - Help :-)

    I am trying to use the name of the image file for the alt tag in the Media editor section, how will i go about this and also would aslo like it to drop the .png or .jpg etc.. also

    @if (Model.value != null){   
    var url = Model.value.image;
    var urlName = "";
    if(Model.editor.config != null && Model.editor.config.size != null){
        url += "?width=" + Model.editor.config.size.width;
        url += "&height=" + Model.editor.config.size.height;
    
        if(Model.value.focalPoint != null){
            url += "&center=" + Model.value.focalPoint.top +"," + Model.value.focalPoint.left;
            url += "&mode=crop";
        }
    }
    
    <img src="@url" class="img-responsive2" alt="">}
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Aug 08, 2016 @ 10:42
    Alex Skrypnyk
    1

    Hi David,

    Agree with you that Monday is hard day :)

    You can try Path.GetFileNameWithoutExtension method:

    string fileName = @"C:\mydir\myfile.ext";
    string result = System.IO.Path.GetFileNameWithoutExtension(fileName);
    

    Thanks,

    Alex

  • David McGawn 37 posts 150 karma points
    Aug 08, 2016 @ 10:45
    David McGawn
    0

    Yeah that is brilliant just what i need, need to figure out how to get the file name to string first into the alt tag :-(

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Aug 08, 2016 @ 10:48
    Alex Skrypnyk
    0
    url.ToString()
    
  • David McGawn 37 posts 150 karma points
    Aug 08, 2016 @ 10:53
    David McGawn
    0

    Yeah thats what i have done so far but that gives me the full media url :-(

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Aug 08, 2016 @ 10:53
    Alex Skrypnyk
    100

    Another one:

    string stringUrl = url;
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Aug 08, 2016 @ 10:54
    Alex Skrypnyk
    0
    string fileName = url.ToString();
    string result = System.IO.Path.GetFileNameWithoutExtension(fileName);
    
  • David McGawn 37 posts 150 karma points
    Aug 08, 2016 @ 10:56
    David McGawn
    0

    Got it i had used the first varible in the alt tag, theses mondays are a killer :-( i had used @fileName #sillyme

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Aug 08, 2016 @ 10:57
    Alex Skrypnyk
    1

    )) So ) Is it fixed?

  • David McGawn 37 posts 150 karma points
    Aug 08, 2016 @ 11:01
    David McGawn
    1

    Yip all working now, your a star :-)

    @if (Model.value != null){
    var url = Model.value.image;
    var urlName = url.ToString();
    string result = System.IO.Path.GetFileNameWithoutExtension(urlName);
    if (Model.editor.config != null && Model.editor.config.size != null)
    {
    url += "?width=" + Model.editor.config.size.width;
    url += "&height=" + Model.editor.config.size.height;
    
    if (Model.value.focalPoint != null)
    {
      url += "&center=" + Model.value.focalPoint.top + "," + Model.value.focalPoint.left;
      url += "&mode=crop";
    }
    }
    
    <img src="@url" class="img-responsive2" alt="@result">
    
    // if (Model.value.caption != null)
    //{
    //    <p class="caption">@Model.value.caption</p>
    // }
     }
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Aug 08, 2016 @ 11:04
    Alex Skrypnyk
    0

    Cool, glad to help you ) Can you mark topic solved?

    Write if something else.

    Thanks,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft