Encode URL in C#

Syntax

HttpUtility.UrlEncode(string s)

HttpUtility.UrlEncode(string s, System.Text.Encoding Enc)

HttpUtility.UrlEncode(byte[] bytes, int offset, int count)

HttpUtility.UrlEncode(byte[] bytes)

Example:

HttpUtility.UrlEncode("http://example.com/page.html?params=@@@/")

Result:

http%3A%2F%2Fexample.com%2Fpage.html%3Fparams%3D%40%40%40%2F


Decode URL in C#

Syntax

HttpUtility.UrlDecode(string s)

HttpUtility.UrlDecode(string s, System.Text.Encoding Enc)

HttpUtility.UrlDecode(byte[] bytes, int offset, int count, System.Text.Encoding e)

HttpUtility.UrlDecode(byte[] bytes, System.Text.Encoding e)

Example:

HttpUtility.UrlDecode("http%3A%2F%2Fexample.com%2Fpage.html%3Fparams%3D%40%40%40%2F")

Result:

http://example.com/page.html?params=@@@/