Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to encode a URL string

Tags:

c#

asp.net

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.

like image 347
anthonypliu Avatar asked May 09 '26 15:05

anthonypliu


1 Answers

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");
like image 118
ptfaulkner Avatar answered May 11 '26 04:05

ptfaulkner