1

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>

Leigh
  • 28,765
  • 10
  • 55
  • 103
Mitchell
  • 253
  • 1
  • 5
  • 16
  • 2
    Yes, it can be done in SQL or in C#. Either one. – Oded Jul 11 '12 at 18:36
  • You can take a look at this question: http://stackoverflow.com/questions/1288046/how-can-i-get-my-webapps-base-url-in-asp-net-mvc. It is very easy to in ASP.Net – jle Jul 11 '12 at 18:36
  • 1
    I thought relative URLs were good and absolute URLs were to be avoided... – lc. Jul 11 '12 at 18:37
  • 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 Jul 11 '12 at 18:42
  • 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 Jul 11 '12 at 18:58

2 Answers2

1

Use a RegExp to find and replace

srini.venigalla
  • 5,137
  • 1
  • 18
  • 29
0

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");
OnResolve
  • 4,016
  • 3
  • 28
  • 50
  • Can't edit the original string in the database so regex will probably be my only choice. I'll look more into it. – Mitchell Jul 11 '12 at 18:41