Adding UTF-8 BOM (Byte Order Mark) To File Output

Explorer ,
Jan 07, 2021 Jan 07, 2021

Copy link to clipboard

Copied

We're exporting some data to CSV files and when using CFFILE (write/append) with CHARSET set to "utf-8", the file seems to be properly encoded, but there's not BOM (byte order mark) at the beginning of the file.

 

As far as I know, this is standard practice as the BOM is optional.  Some applications (like Notepad) open the file just fine, and render the UTF-8 accented characters, angled quotations, etc. just fine.

 

Excel, however, has issues when opening the file if the BOM is not present.  If I manually add the BOM to the beginning of the file using another application, Excel opens it fine (and so does Notepad).

 

Is there a simple / recommended way to add the BOM to the file using CFFILE or other built-in functionality?

 

The BOM character entry in UTF-8 is U+FEFF (65279) or EF, BB, BF in raw hex.  So currently, I'm starting our file output with CHR(65279), and this does seem to work.

 

Thanks

Views

179

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Explorer , Jan 11, 2021 Jan 11, 2021
From my previous post:So currently, I'm starting our file output with CHR(65279), and this does seem to work. I was just wondering if this is the "correct" way to do it, or if there was some other recommended way.

Likes

Translate

Translate
Adobe Community Professional ,
Jan 09, 2021 Jan 09, 2021

Copy link to clipboard

Copied

You should try something like:

<cfset OutputContent=chr(65279) & "abbcccdddd some arbitrary text content">

<cfset absolute_path_to_output_file="C:\Users\BKBK\Desktop\output.txt">

<cffile action = "write" file = "#absolute_path_to_output_file#" output = "#OutputContent#" charset="UTF-8">

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 11, 2021 Jan 11, 2021

Copy link to clipboard

Copied

From my previous post:

So currently, I'm starting our file output with CHR(65279), and this does seem to work.

 

I was just wondering if this is the "correct" way to do it, or if there was some other recommended way.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

LATEST

Oh, I see. I wasn't so sure about what you meant, so focused on the ColdFusion question, "Is there a simple / recommended way to add the BOM to the file using CFFILE or other built-in functionality?". So, we both have the same idea. And that is the "correct" way as far as I know.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines