Chris Fewtrell
Chris Fewtrell

Reputation: 7715

Easiest way to Url Path Encode?

I want to reliably and easily Uri encode paths such as "/folder/foo%bar" to "/folder/foo%25bar".

I would have hoped that HttpUtility.UrlPathEncode would do the trick but this method only escapes spaces. I don't want to url HttpUlity.UrlEncode as this will encode "foo bar" to "foo+bar" - which ain't what I want.

Upvotes: 2

Views: 1123

Answers (1)

Xander
Xander

Reputation: 1133

public static string CustomURLEncode(string str)
{
       return System.Web.HttpUtility.UrlEncode( str ).Replace(”+”,”%20″);
}

Upvotes: 4

Related Questions