EDI Flat File parsing with C#?

ElHaix picture ElHaix · Jan 12, 2010 · Viewed 30.9k times · Source

Initially I was thinking to use SSIS to parse an EDI file, however I've seen a few manual EDI parsers (field mapping), and would like to use automate this functionality in C#.

Example EDI File:

Example EDI File

Answer

cleftheris picture cleftheris · Aug 2, 2016

There is EDI.Net library which is opensource and supports all three known EDI formats (X12, EDIFact, Tradacoms). In your case for X12 you need to provide a custom implementation of the IEdiGrammar with the following presets.

public class EDI_X12Grammar : IEdiGrammar
{
...
}

var grammar = new EDI_X12Grammar() 
       {
            ComponentDataElementSeparator = new[] { '>' },
            DataElementSeparator = new[] { '*' },
            DecimalMark = null,
            ReleaseCharacter = null,
            Reserved = new char[0],
            SegmentTerminator = '~',
            ServiceStringAdviceTag = null,
            InterchangeHeaderTag = "ISA",
            FunctionalGroupHeaderTag = "GS",
            MessageHeaderTag = "ST",
            MessageTrailerTag = "SE",
            FunctionalGroupTrailerTag = "GE",
            InterchangeTrailerTag = "IEA",
        };

Disclaimer I wrote the library.