UrlEncode through a console application?


Question

Normally I would just use:

HttpContext.Current.Server.UrlEncode("url");

But since this is a console application, HttpContext.Current is always going to be null.

Is there another method that does the same thing that I could use?

1
61
2/29/2012 7:35:42 PM

Accepted Answer

Try this!

Uri.EscapeUriString(url);

Or

Uri.EscapeDataString(data)

No need to reference System.Web.

Edit: Please see another SO answer for more...

78
2/20/2018 10:04:25 PM

I'm not a .NET guy, but, can't you use:

HttpUtility.UrlEncode Method (String)

Which is described here:

HttpUtility.UrlEncode Method (String) on MSDN


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon