2

I have a string that contains a url which looks like this:

http://www.test.com/images/tony's pics.jpg

I need the url to look like this:

http://www.test.com/images/tony%27s%20pics.jpg

How would I programmatically solve this with a url in a STRING form. Thanks.

anthonypliu
  • 12,179
  • 28
  • 92
  • 154
  • 1
    See this answer here http://stackoverflow.com/questions/575440/url-encoding-using-c-sharp/575843#575843 – Mob Nov 11 '11 at 01:07
  • Dupe of http://stackoverflow.com/questions/1461223/how-do-i-encode-an-url ? – Robert Nov 11 '11 at 01:10

2 Answers2

9

I would think this would easily be solved by using the HttpUtility UrlEncode:

string url = "http://www.test.com/images/" + HttpUtility.UrlEncode("tony's pics.jpg");
ptfaulkner
  • 712
  • 4
  • 14
  • 1
    This is going to result in http%3a%2f%2fwww.google.com%2fsearch%3fq%3dExample – Mob Nov 11 '11 at 01:10
0

Have a look at UrlEncode of the HttpServerUtility:

HttpServerUtility.UrlEncode("http://www.test.com/images/tony's pics.jpg");
Mike Dinescu
  • 54,171
  • 16
  • 118
  • 151