How do I replace all the spaces with %20 in C#?

Solution 1:

Another way of doing this is using Uri.EscapeUriString(stringToEscape).

Solution 2:

I believe you're looking for HttpServerUtility.UrlEncode.

System.Web.HttpUtility.UrlEncode(string url)

Solution 3:

I found useful System.Web.HttpUtility.UrlPathEncode(string str);

It replaces spaces with %20 and not with +.