November Happy Hour will be moved to Thursday December 5th.

Convert Permanent Link for Image to Virtual

Vote:
 

 

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);

 

Thanks,

Victor

#39613
May 25, 2010 11:29
Vote:
 

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?

#39627
May 26, 2010 9:35
Vote:
 

This works in my CMS 6 installation:

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

PermanentLinkMapStore.ToMapped(url);

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

Hello,

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.

Cheers,


Victor

#39636
May 26, 2010 15:13
Vote:
 

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.

#39638
May 26, 2010 15:35
* 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.