Major challange - convert relative src to absolute

Vote:
 

Hi all!

I have some properties on a page that are 'URL to an image'. They look like this (yes I will correct the missing alt atribute)

<img src="<%= CurrentPage["pp_theIMG"] %>" alt="" />

    

The problem is that the path to the image is a relative one, like this: /Global/image01.png. The reason for the problem is that they dont show up in hotmail when the page is sent as a newsletter.

So, I want to convert them to absolute, like this: http://www.MySite/Global/image01.png


This takes some code behind I guess, and I'am not totally lost. I have made this method:

        public string imgSRC(string sample)
        {
            string result = sample.Replace("/Global/", "http://www.MySite/Global/");
            return result;
        }

    

In the front end code I tried this:

<%= imgSRC ("/Global/") %>

    

But that just writes the new path directly to the page. I want to have it in the property pp_theIMG.


I would be mighty thankfull If someone could help me with this problem. Iam expected to get this newsletter done. By the way, making newsletters for hotmail is like going back 10 years in html and css.

#53147
Aug 30, 2011 6:23
Vote:
 

Any other way of doing this would also be helpful ofcourse. And please, explain well, Iam rather new to this.

#53152
Aug 30, 2011 8:46
Vote:
 

Doh. I can just add the domain in the property. It would be more handy to have them all replaced though.

<img src="<%= http://mySiteCurrentPage["pp_theIMG"] %>" alt="" />

    

#53153
Edited, Aug 30, 2011 8:54
Vote:
 

The absolute URL to the image depends on site settings in your web.config. I believe that it's better to store relative URL to image as page property and generate absolute URL using UriSupport.AbsoluteUrlBySettings method. when page is rendered/"sent" as newsletter.

#53159
Aug 30, 2011 13:03
Vote:
 

Any chance you are using EPiServer Mail to send your newsletter? EPiServer Mail automatically converts the URLs to absolue. In that case, if they don't show up on hotmail it's either because they are blocked or some setting in EPiServer.config or EPiServerMail.config is wrong so the URLs aren't converted correctly.

#53161
Aug 30, 2011 13:24
Vote:
 

Thank you guys (really appriciete your help). No Iam using the "Send page as mail" function in Internet Explorer, then it gets sent by Outlook.

My way, decribed above worked and the images display in hotmail. So problem solved for the moment. Another thing is that hotmail strips all css in the header so I have to work with inline. That becomes a big deal with edit boxes where editor content generates p tags.

 

Dmytro Duk: that sounds interesting and I will look into it when I have more time. Thank you very much.

#53162
Aug 30, 2011 13:46
Vote:
 

But anyway, it would be fantastic to know: is there a way to make c# code to find every /Global/ in the front end code and convert it to another string? Is it hard to do?

#53164
Edited, Aug 30, 2011 14:09
Vote:
 

You could probably do it with a response filter but I wouldn't say that is necessarily simple. I fear it would be regex hell if you want to make sure you don't change any "legitimate" /Global/ strings referring to something else (say the edit text describes such an URL in an example).

On response filters: http://www.4guysfromrolla.com/articles/120308-1.aspx

#53167
Aug 30, 2011 14:35
Vote:
 

Ok I look into it. Thanks again.

#53168
Aug 30, 2011 14:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.