UrlEncode Method
Collapse the table of content
Expand the table of content

HttpUtility.UrlEncode Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Converts a text string into a URL-encoded string.

Namespace:  System.Net
Assembly:  System.Windows (in System.Windows.dll)

public static string UrlEncode(
	string url
)

Parameters

url
Type: System.String
The text to URL-encode.

Return Value

Type: System.String
A URL-encoded string.

If characters such as blanks and punctuation are passed in an HTTP stream, they might be misinterpreted at the receiving end. URL encoding replaces characters that are not allowed in a URL with character-entity equivalents consisting of hexadecimal escape sequences. The converted string is expected to conform to the UTF-8 format.

URL encoding replaces all character codes except for letters, numbers, and the following punctuation characters:

  • - (minus sign)

  • _ (underscore)

  • . (period)

  • ! (exclamation point)

  • * (asterisk)

  • '(single quotation mark)

  • ( and ) (opening and closing parentheses)

For example, when embedded in a block of text to be transmitted in a URL, the characters < and > are encoded as %3c and %3e.

The UrlDecode method reverses the encoding.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft