I am generating CSV file which contains double byte characters. Right now I am using BinaryWriter with UTF-8 encoding. Problem is that generated CSV file has BOM prefix(preamble). How can I remove the preamble?
I am adding preamble to BinaryWriter because without it, it still shows unrecognized characters instead of double byte characters.
I tried using different encoding constructor for example: Dim encoding As New System.Text.UTF8Encoding(False)
which didn't work.
Dim encoding As Encoding = Encoding.UTF8
Using bw As New BinaryWriter(fs, encoding)
bw.Write(encoding.GetPreamble())
bw.Write(data)
bw.Flush()
Using n As New Ionic.Zip.ZipFile(encoding)
n.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression
fs.Position = 0
n.AddEntry(fileName, fs)
Response.Clear()
Response.ContentType = "application/octet-stream"
n.Save(Response.OutputStream)
End Using
bw.Close()
bw.Dispose()
End Using
This code will generate correct CSV file in Zip file with correct double byte characters but with preamble as prefix of whole data like: "���"
I want to remove this unrecognized prefix, but by removing the line: bw.Write(encoding.GetPreamble())
I lose whole encoding and double byte characters appear as not recognized and prefix is still there.
Changing the encoding constructor to: Dim encoding As New System.Text.UTF8Encoding(False)
broke the encoding as well.