Convert Permanent Link for Image to Virtual



Hello there

Does anyone know how to change a Permanent Link such as “~/link/e76463a4b3604b51952312ca0e404bcd.gif” into a virtual link such as “/Global/images/myimage.jpg”?

There’s a tool to do it for Pages but I haven’t found anything for images.

This is what I’ve tried so far but I keep getting the permanent link or nothing at all:


            string mappedLink = item.ToMappedLink();

            string permanentLink = item.ToPermanentLink();

            var url = new UrlBuilder(item.Href);

            bool result = PermanentLinkMapStore.ToMapped(url);

            string test = result ? url.ToString() : item.Href;

            string str;
            PermanentLinkMapStore.TryToMapped(uriToImage, out str);




May 25, 2010 11:29

Is your source for the image link a LinkCollection property? If you just render it using the property web control, will it display a link to the correct virtual path of the image?

May 26, 2010 9:35

This works in my CMS 6 installation:

string permanentLink = "~/link/9abeeb4114cd4c129187aa2562eaa849.jpg";
UrlBuilder url = new UrlBuilder(permanentLink);


lblTest.Text = url.ToString();
Edited, May 26, 2010 12:07


Thank you for your response.

The source is not a LinkCollection but a regular URL to Image Property.

I tried using the PermanentLinkMapStore before but I still cannot get the virtual path.



May 26, 2010 15:13

What if you get the PropertyData and ToString it rather than trying to get it's value? I think this is what the Property control does in this case. Do something like this:

string url;

PropertyData data = page.Property["MyProperty"];

if ((data == null || data.IsNull) { // Fallback here }

url = data.ToString();

In there somewhere it uses a permanent link map, use Reflector if you want to dig further into the details.

May 26, 2010 15:35