Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 72043

To generate CSV file in UTF-8 without BOM

$
0
0

My current system exports data to CSV in UTF-16 encoding format which I modified by adding 65001 UTF format to generate UTF-8 file. The exported file is UTF-8 with BOM. Here the end client requires just UTF-8 without those starting bytes with BOM. Any help or suggestion is really appreciable.

The following is my code:

    select firstOnly * from integrationParameters;
    fileName = integrationParameters.LocalPath + 'CustInvoice' + todaysDate + '.csv';
    perm     = new FileIoPermission(fileName, 'w');
    perm.assert();
    file = new TextIo(fileName, 'w', 65001);
I tried to modify it based on some reference from the community's older posts but it puts-up an error saying 
"System.IO.IOException: The process cannot access the file '\\Axtedev\test\CustInvoice20190916.csv' because it is being used by another process."
Following is the modified code
    str                         lobValue;
    System.Text.Encoding        encoding   = new System.Text.UTF8Encoding(false);
    InteropPermission           permO      = new InteropPermission(InteropKind::ClrInterop);
    
    #File
    select firstOnly * from integrationParameters;
    fileName = integrationParameters.LocalPath + 'CustInvoice' + todaysDate + '.csv';
    perm     = new FileIoPermission(fileName, 'w');
    perm.assert();
    file = new TextIo(fileName, 'w', 65001);

    permO.assert();
    System.IO.File::WriteAllText(fileName, System.IO.File::ReadAllText(fileName), encoding);

Viewing all articles
Browse latest Browse all 72043

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>