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>

5
  • 2
    Yes, it can be done in SQL or in C#. Either one. Commented Jul 11, 2012 at 18:36
  • You can take a look at this question: stackoverflow.com/questions/1288046/…. It is very easy to in ASP.Net Commented Jul 11, 2012 at 18:36
  • 1
    I thought relative URLs were good and absolute URLs were to be avoided... Commented Jul 11, 2012 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! Commented Jul 11, 2012 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. Commented Jul 11, 2012 at 18:58

2 Answers 2

1

Use a RegExp to find and replace

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Can't edit the original string in the database so regex will probably be my only choice. I'll look more into it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.