• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1228
  • Last Modified:

Get Encoding From byte array

In my app, HTML is downloaded from server an stream to a byte array. But I don't know how to detect its encoding. Encoding of these html can be iso8859-1 or UTF-8.

My code :

byte[] objDataArray = ...

System.Text.UTF8Encoding objEncoding = new System.Text.UTF8Encoding();
string strData = objEncoding.GetString(objDataArray);

-- > if encoding of html is iso8859-1, strData will not correct

Please help me !
1 Solution
try checking for a byte order mark using the UTF8Encoding.GetPreamble method, see msdn link:


If there is no preamble you can just guess. May be there is a field in the http header indicating the encoding.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now