3

I have asp page which creates csv file. The problem is that this csv file is created as UTF-8 WITHOUT BOM and when I open it, some signs are not visible correctly. What should I change to save it as UTF-8 WITH BOM? If I convert it to UTF-8 WITh BOM manially in notepad++, it works.

Thanks.

    Response.Clear
    Response.ContentType = "application/vnd.ms-excel; charset=UTF-8;"
    Response.AddHeader "Content-Disposition", "attachment; filename=goodsTransfer.csv"
    Response.Charset = "UTF-8"
    Response.Write "all my data"
    Response.end
mrk
  • 4,999
  • 3
  • 27
  • 42
Simon
  • 1,955
  • 5
  • 35
  • 49

2 Answers2

4

Try:

Response.Write(ChrW(65279) & "all my data")
Esailija
  • 138,174
  • 23
  • 272
  • 326
  • 2
    It works. Thank you. But what does it means. As i understand, it is BOM that indicates that this is UTF-16 file: (FEFF is in decimal 65279) From wikipedia: "UTF-16, a BOM (U+FEFF) may be placed as the first character of a file or character stream to indicate the endianness (byte order) of all the 16-bit code units of the file or stream." But i can open it with notepad++, which supports only UTF-8. Can you explain me a bit? Thanks. – Simon Mar 29 '13 at 11:36
  • As described in https://stackoverflow.com/a/17879474/416542: The character \ufeff is used for all UTF encodings. In fact this character actually is encoded as 0xEFBBBF in UTF-8 as stated in Wikipedia. – walderich Aug 26 '21 at 10:54
0

The correct BOM for UTF-8 is:

Response.Write(ChrW(&HeF) & ChrW(&Hbb) & ChrW(&HbF) & "all my data")
Mark Cilia Vincenti
  • 1,410
  • 8
  • 25