Name

ContentEncoding

Synopsis

Encoding = Response.ContentEncoding
Response.ContentEncoding = Encoding

Returns an instance of the Encoding class representing the encoding of the current response. The Encoding class exposes properties and methods that allow you to examine and modify the system’s character encoding -- i.e., the way in which characters are stored internally in the system. For example, you can convert a Unicode string to ASCII, UTF-7, or UTF-8.

Parameters

Encoding

An Object variable of type Encoding. Its EncodingName property provides the human-readable name of the encoding type.

Example

The example uses the properties of the Encoding class instance returned from the ContentEncoding property to display the human-readable name and the registered (IANA) name of the current encoding.

Sub Page_Load(  )
   Message.Text = "Current encoding is " & _
      Response.ContentEncoding.EncodingName & "<br/>"
   Message.Text &= "Current encoding IANA name is " & _
      Response.ContentEncoding.WebName & "<br/>" 
End Sub

Notes

The ContentEncoding property is new in ASP.NET and provides a richer interface for examining and modifying character set and code page information for the current response. It also provides the only way to convert one character-encoded string to another character encoding (i.e., Unicode to ANSI).

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.