Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / Read CSV with values e...
Finance forum
Suggested answer

Read CSV with values enclosed with double quotes with comma

Posted on by 4
Hello guys,
 
I'm stucked in one custom csv file import process. Your help much appreciated.
following steps as below,
1. I am uploading file using temporary storage class as below
FileUploadTemporaryStorageResult fileUpload  = File::GetFileFromUser() as FileUploadTemporaryStorageResult; 
2. To read file content I am using ASCIIStreamIO as below
AsciiStreamIo file        = AsciiStreamIo::constructForRead(fileUpload.openResult());
file.inFieldDelimiter(','); //separator
file.inRecordDelimiter('\r\n');
3. to read file content in container inside while loop
Container con = file.read();
 
above working fine but facing issue when csv column has value with comma.
for example we one column has value like "Test1,Test2"  in this case container getting two seperate element as "Test1 and Test2".
It should consider Test1,Test2 as single element.
 
I tried same with CommaStreamIO, CommaTextStreamIO, TextStreamIO  but still same result.
 
Please help me on this.
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 229,067 Most Valuable Professional on at
    Read CSV with values enclosed with double quotes with comma
    F&O can handle that. For example, try this code:
    str text = '"a","x,y,z","b"';
    var encoding = System.Text.Encoding::UTF8;
    using (var stream = new System.IO.MemoryStream(encoding.GetBytes(text)))
    {
        CommaTextStreamIo io = CommaTextStreamIo::constructForRead(stream);
        container values = io.read();
    }
    You'll get a container with three values, as intended:
     
     
    Using AsciiStreamIo sounds suspicious to me, because you rarely run into ASCII files these days.
  • Suggested answer
    Read CSV with values enclosed with double quotes with comma

    Edit: Disregard my answer 😇

    No out-of-the-box methods in F&O can handle this, unfortunately.

    I haven’t tested it, but the CSV importer used for tax services implements the TextFieldParser from VisualBasic, which can handle this scenario. I’d suggest copying that method into your own class.

     
    Method: TaxServiceTaxFeatureSetupCsvImporter.getHeaderFieldMapFromStr(str __strLine)
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Forum Structure Changes Coming Soon!

Quick Links

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,782 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,067 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,150

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans