3

I'm using this method to write to a MemoryStream object, which is subsequently stored a binary in SQL. It is being used to read in .HTML files from the file system on Windows.

How do I know which type of encoding this data is being read in as? Thanks.

Ryan Peters
  • 7,608
  • 8
  • 41
  • 57

2 Answers2

9

None, because it opens a binary stream. When you e.g. wrap stream into a StreamReader, that's the moment you choose the encoding. The FileStream itself as returned by the OpenRead method is not text based and thus does not have an encoding.

Pieter van Ginkel
  • 29,160
  • 8
  • 71
  • 111
1

FileInfo.OpenRead returns a raw stream that does not use any encoding (since it returns bytes, not characters).

Encodings are used to convert raw bytes into Unicode characters.
In .Net, encodings are used by the StreamReader and StreamWriter classes, which work with strings instead of bytes.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964