Alt tag for image


This somes like a really obvious thing but I cannot find any information about it anywhere. I have a property of type Url with the UiHint.Image decoration applied to it. I want to render that image on my page along with the description applied in the file manager as an alt tag. My thoughts where to modify the DisplayTemplate for the image. I have the following code to get the alt tag:

var file = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(virtualPath) as UnifiedFile;
var alt = file != null && file.Summary.Dictionary["Description"] != null ? file.Summary.Dictionary["Description"].ToString() : string.Empty;


The problem I am having however is the data that I have available for me is just of type EPiServer.Url, from this I need to find out what the virtualpath for that url is.

Does anyone know how I can obtain this, or have a better suggestion on how to do it?

Many Thanks

Sep 05, 2013 15:32

Try using the PermanentLinkMapper class and TryToMapped() method.


Sep 05, 2013 19:14

Hi Frederik

Thank you for your response!!! Unfortunately the URL that comes back is tho relative mapped path, not the original Virtual Path. Any other thoughts?

Many thanks

Sep 06, 2013 17:43

Hi All

Has anyone got any idea on this? There has to be a way to get an alt tag for an image.

Thanks very much

Sep 23, 2013 15:55

Hi all

For future reference I have got it working, it was as simple as URLDecoding first, I have written an extension method which I am just calling from my DisplayTemplate and a few other places where I am outputting images, works perfectly. Code below if it helps anyone:

public static string GetDescription(this Url url)
            var description = string.Empty;
            var virtualPath = HttpUtility.UrlDecode(url.ToString());
            var file = VirtualPathHandler.Instance.GetFile(virtualPath, true) as UnifiedFile;

            if (file != null)
                description = file.Summary.Dictionary["Description"] != null
                                  ? file.Summary.Dictionary["Description"].ToString()
                                  : string.Empty;

            return description;



Oct 07, 2013 17:42
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.