Create a csv file with UTF-8 Encoding (Without BOM)

Hello,

I am writing a csv file with the encoding option with value “utf-8” as described in this link Supported Character Encoding but it writes with the utf-8 bom encoding.

I have read some replies for related questions but not succeed with those replies.

Could you help me please. Also, I need explanation how that encoding option works cause when I put UTF8Encoding(False) I got an error.

Thank you in advance,

@christian.2a

Did you happen to try this

Cheers

Thanks for the reply. Yes, but I don’t understand how the parameters works. I want to understand what does “abc.text” and “Hello File” parameters means. Are they file paths, file names or what?

@christian.2a

The first is file and second is the content… here for more context

In the above thread I guess true or false is one more parameter to be added

Cheers

Hi,

FYI, hope the following sample help you.

Sample20230620-1.zip (3.0 KB)

Regards,

Can I put like this:

File: file path
Text: datatable (from the read activity above)
Encoding: new UTF8Encoding(False)

Cause it shows me a message:
File does not have a public static method named “WriteAllText” matching the parameters types, generic type arguments, and generic type constraints supplied to InvokeMethod ‘InvokeMethod’

@christian.2a

The second one should be a string any not datatable…

you can do the read csv also using read text file activity so that the data is read as text and use that text output in place of the datatable

Data is where you need to pass the string output from read text file by reading the csv file using a read text file activity

cheers

Oh I see, so the invoke method activity should be after the read text file activity and the the write csv activity?

Another question, where do I put the output from the invoke method activity?

@christian.2a

You dont need a write csv again…

What the invoke method does is it would convert the given string into the specified encoding and will write the data into the text file provided…you can provide the file name as .csv in the invoke method itself

So your first activity would be read text file to read csv as text and then invoke method to convert and write to a file again(and this can be written to csv directly if you need a csv output)

Cheers

So, I have a csv file, but when I put that file in the read text file activity is shows one or more error occurred.

My sequence is read text file → invoke method → write csv.

** read text file: csv file path as file name

** invoke method:

  • File: file path of new csv file
  • Text: data (string)
  • Encoding: New System.Text.UTF8Encoding(false)

**write csv

  • write to what file: csv file path
  • write from: data (here I need a datable for the activity) but this variable is String

@christian.2a

Please check this …this is how it should look and no write csv is needed

Read csv with read text and then invoke

I did check and it is giving output as expected

cheers

Nice! Thank you @Anil_G

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.