This documentation is archived and is not being maintained.

HttpWebResponse.CharacterSet Property

Gets the character set of the response.

[Visual Basic]
Public ReadOnly Property CharacterSet As String
public string CharacterSet {get;}
public: __property String* get_CharacterSet();
public function get CharacterSet() : String;

Property Value

A string containing the character set of the response.


Exception Type Condition
ObjectDisposedException The current instance has been disposed.


The CharacterSet property contains a value describing the character set of the response. This character set information is taken from the header returned with the response.


[Visual Basic, C#, C++] The following example obtains the character set of the response.

[Visual Basic] 
   Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
   Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
   Console.WriteLine(("The encoding method used is: " + myHttpWebResponse.ContentEncoding))
   Console.WriteLine(("The character set used is :" + myHttpWebResponse.CharacterSet))
   Dim seperator As Char = "/"c
   Dim contenttype As [String] = myHttpWebResponse.ContentType
   ' Retrieve 'text' if the content type is of 'text/html.
   Dim maintype As [String] = contenttype.Substring(0, contenttype.IndexOf(seperator))
   ' Display only 'text' type.
   If [String].Compare(maintype, "text") = 0 Then
      Console.WriteLine(ControlChars.NewLine + " Content type is 'text'.")

        HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
        HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 

        Console.WriteLine("The encoding method used is: " + myHttpWebResponse.ContentEncoding);
        Console.WriteLine("The character set used is :" + myHttpWebResponse.CharacterSet);

        char seperator = '/';
        String contenttype = myHttpWebResponse.ContentType;
        // Retrieve 'text' if the content type is of 'text/html.
        String maintype = contenttype.Substring(0,contenttype.IndexOf(seperator));
        // Display only 'text' type.
        if (String.Compare(maintype,"text") == 0) 
            Console.WriteLine("\n Content type is 'text'.");

try {
   HttpWebRequest* myHttpWebRequest =
   HttpWebResponse* myHttpWebResponse =

   Console::WriteLine(S"The encoding method used is: {0}",
   Console::WriteLine(S"The character set used is : {0}",

   char separator = '/';
   String*  contenttype = myHttpWebResponse->ContentType;
   // Retrieve 'text' if the content type is of 'text/html.
   String*  maintype = contenttype->Substring(0, contenttype->IndexOf(separator));
   // Display only 'text' type.
   if (String::Compare(maintype, S"text") == 0) {
      Console::WriteLine(S"\n Content type is 'text'.");

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

HttpWebResponse Class | HttpWebResponse Members | System.Net Namespace