1
votes

I'm calling stored procedure that returns html of an article I plan to email out to my users. However, some of the articles have images that will have broken links because the addresses are incomplete.

What I'd like to do, either within the stored procedure or my asp.net code that gets the string, is insert within the long string the correct http: of my website. So I'd look for /portalname/etc. then insert in front of it www.website.com in front of it. Can this be done in SQL or is there a function in C# that I can use to insert that within the string?

EDIT: Here's an example of the kind of string I'm getting. I'd like to change the url to an absolute one either in the store procedure or the code.

<p><span style="text-decoration: underline;"><strong><img alt="" src="/portalname/portals/0/Images/SomeImg.jpg" style="margin-right: 10px; margin-bottom: 10px; float: left;" /><span style="font-size: 12px; font-family: arial;"> TITLE</span></strong></span></p> <p><span style="font-size: 12px; font-family: arial;">Article Summary strong.&nbsp;&nbsp; </span></p>

2
Yes, it can be done in SQL or in C#. Either one. - Oded
You can take a look at this question: stackoverflow.com/questions/1288046/…. It is very easy to in ASP.Net - jle
I thought relative URLs were good and absolute URLs were to be avoided... - lc.
What if your www.website.com changes down the road? You'd have another project like this. Do it in your asp.net pages based on a config. Heck, you might host the images on a CDN some day! - n8wrl
I read for emails absolutes are needed to get images to display correctly otherwise I get a broken image. The current relative URL's won't work in the emails so I'm resorting to absolute. As for the database it's a database on our servers. We've set up our website to add the html of the summary on our articles into the database. I then take that summary and add it into an email to send out to users. - Mitchell

2 Answers

1
votes

Use a RegExp to find and replace

0
votes

Regex if you can't edit the format of the string in the database, or if you can, replace instances with the {<num>} syntax so that you can use the String.Format() function on the returned string.

This is my example article that has {0} as a resource.

var formatted = String.Format(stringFromDB, "http://example.org");