Change Encoding of Export or File

The purpose of this Action example is to illustrate how to use an Action to convert encoding of files. 

This example is provided as inspiration only. It must be adapted to your Perfion environment to work. Perfion Support does not assist with such adaptations. Please contact your Perfion Partner or your Perfion consultant if you need assistance.

The default behavior of WRITE.CSV is to output the file in UTF-8, but sometimes you may wish have your output in different encoding. 

To do this, you can use the EXECUTE.SCRIPT command on your output file after doing the WRITE.CSV:

 

An importable example of the action can be found here: 

The Action utilises .Nets System.Text.Encoding methods to write the file into the desired encoding. Please see GetEncoding() and  Encoding for more information

Sample data for building Action Map

Data must be adapted to your Perfion enviroment to work.

Action Map - From

To

Command

Action

Script

Note

.

tbl_products

SELECT.PERFION

 

<Query>
   <Select languages='EN' maxCount='5'>
      <Feature id='**' view='Config' />
   </Select>
   <From id='100' />
   <Where>
   </Where>
</Query>

Select 5 products to use in the example

table

@Format

 

 

 

 

tbl_products

C:\temp\export.csv

WRITE.CSV

 

 

Write result to CSV. This export will be encoded in UTF-8  as that is the standard in Perfion

C:\temp\export.csv

C:\temp\exportANSI.csv

EXECUTE.SCRIPT

 

File.WriteAllText( P.To, File.ReadAllText( P.From ), System.Text.Encoding.GetEncoding(1252));

The File.WriteFile() method creates a new file based on another source. 

The last argument can be used to select an encoding. 

Please note that you can have the same filename in the To and From columns to avoid creating multiple files