CXLSX
CXLSX

Reputation: 65

SSIS Encode a .raw or .txt file from ANSI to UTF-8 without BOM using C#

I am working on a fairly simple SSIS package, which reads from DB2 using ODBC Source and taking it to a flat file destination. But I need this file that is generated to be UTF-8 (without BOM) and not ANSI as it is automatically generated by SSIS. The closest thing that has worked for me is the code below, but it converts it to UTF-8 BOM and the client tells me that the file with BOM does not work for him. Is there any way I can make the file UTF-8?

string srcFilename = Dts.Variables["User::FFDestPath"].Value.ToString();
string text = File.ReadAllText(srcFilename);
File.WriteAllText(srcFilename, text, System.Text.Encoding.UTF8);
Encoding utf8WithoutBom = new UTF8Encoding(false);

Edit: enter image description here enter image description here

Upvotes: 1

Views: 1028

Answers (1)

billinkc
billinkc

Reputation: 61211

For writing natively in SSIS, in your Flat File Connection manager, specify the Code Page is 65001 (UTF-8).

enter image description here

When the Flat File Destination writes a file, there is no BOM written.

enter image description here

Upvotes: 1

Related Questions