private void btnTranslate_Click(object sender, System.EventArgs e)
        {
            ediDocument oEdiDoc = null;
            ediSchema oSchema = null;
            ediSchemas oSchemas = null;
            ediDataSegment oSegment = null;
            string sSegmentID = "";
            string sLoopSection = "";
            int nArea = 0;
            string sValue = "";
            string sNadPartyQlfr = "";

            string sPath = AppDomain.CurrentDomain.BaseDirectory;
            string sSefFile = "DESADV_D96A.EVAL0.SEF";
            string sEdiFile = "desadv.edi";
 
            //CREATES EDIDOC OBJECT
            ediDocument.Set(ref oEdiDoc, new ediDocument());
 
            //THIS MAKES CERTAIN THAT FREDI ONLY USES THE SEF FILE PROVIDED, AND THAT IT DOES 
            //NOT USE ITS BUILT-IN STANDARD REFERENCE TABLE TO GENERATE THE EDI FILE.
            ediSchemas.Set(ref oSchemas,(ediSchemas) oEdiDoc.GetSchemas());
            oSchemas.EnableStandardReference = false;
 
            //THIS OPTIONS STOPS FREDI FROM KEEPING ALL THE SEGMENTS IN MEMORY
            oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardOnly;
 
            //SPECIFY TERMINATORS
            oEdiDoc.SegmentTerminator = "'";
            oEdiDoc.ElementTerminator = "+";
            oEdiDoc.CompositeTerminator = ":";
            oEdiDoc.ReleaseIndicator = "?";
 
            //LOADS THE SEF FILE
            ediSchema.Set(ref oSchema, (ediSchema) oEdiDoc.LoadSchema(sPath + sSefFile, 0));
 
            //LOADS THE EDI FILE
            oEdiDoc.LoadEdi(sPath + sEdiFile);
 
            //GETS THE FIRST DATA SEGMENT
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oEdiDoc.FirstDataSegment);
 
            //LOOP THAT WILL TRAVERSE THRU EDI FILE FROM TOP TO BOTTOM
            while ( oSegment != null )
            {
                //DATA SEGMENTS WILL BE IDENTIFIED BY THEIR ID, THE LOOP SECTION AND AREA
                //(OR TABLE) NUMBER THAT THEY ARE IN.
                sSegmentID = oSegment.ID;
                sLoopSection = oSegment.LoopSection;
                nArea = oSegment.Area;
 
                if (nArea == 0)
                {
                    if (sLoopSection == "")
                    {
                        if (sSegmentID == "UNB")
                        {
                            sValue = oSegment.get_DataElementValue(1,1);     //Syntax identifier
                            sValue = oSegment.get_DataElementValue(1,2);     //Syntax version number
                            listBox1.Items.Add("Interchange sender id: " + oSegment.get_DataElementValue(2,1));     //Interchange sender identification
                            sValue = oSegment.get_DataElementValue(2,2);     //Partner identification code qualifier
                            sValue = oSegment.get_DataElementValue(2,3);     //Interchange sender internal identification
                            listBox1.Items.Add("Recipient id: " + oSegment.get_DataElementValue(3,1));     //Recipient identification
                            sValue = oSegment.get_DataElementValue(3,2);     //Partner identification code qualifier
                            sValue = oSegment.get_DataElementValue(3,3);     //Routing address
                            sValue = oSegment.get_DataElementValue(4,1);     //Date
                            sValue = oSegment.get_DataElementValue(4,2);     //Time
                            listBox1.Items.Add("Interchange control reference: " + oSegment.get_DataElementValue(5,0));     //Interchange control reference
                        }   //sSegmentID
                    }   //sLoopSection
                }
                else if (nArea == 1)
                {
                    if (sLoopSection == "")
                    {
                        if (sSegmentID == "UNH")
                        {
                            listBox1.Items.Add("Message reference number: " + oSegment.get_DataElementValue(1,0));     //Message reference number
                            sValue = oSegment.get_DataElementValue(2,1);     //Message type identifier
                            sValue = oSegment.get_DataElementValue(2,2);     //Message version number
                            sValue = oSegment.get_DataElementValue(2,3);     //Message release number
                            sValue = oSegment.get_DataElementValue(2,4);     //Controlling agency
                            sValue = oSegment.get_DataElementValue(2,5);     //Association assigned code
                        }
                        else if (sSegmentID == "BGM")
                        {
                            listBox1.Items.Add("Message coded name: " + oSegment.get_DataElementValue(1,1));     //Document/message name, coded
                            sValue = oSegment.get_DataElementValue(1,2);     //Code list qualifier
                            sValue = oSegment.get_DataElementValue(1,3);     //Code list responsible agency, coded
                            sValue = oSegment.get_DataElementValue(1,4);     //Document/message name
                            listBox1.Items.Add("Document message number: " + oSegment.get_DataElementValue(2,0));     //Document/message name
                        }
                        else if (sSegmentID == "DTM")
                        {
                            sValue = oSegment.get_DataElementValue(1,1);     //Date/time/period qualifier
                            listBox1.Items.Add("Document Date: " + oSegment.get_DataElementValue(1,2));     //Date/time/period
                            sValue = oSegment.get_DataElementValue(1,3);     //Date/time/period format qualifier
                        }
                        else if (sSegmentID == "MEA")
                        {
                            sValue = oSegment.get_DataElementValue(1,0);     //Date/time/period format qualifier
                            sValue = oSegment.get_DataElementValue(2,1);     //Property measured, coded
                            sValue = oSegment.get_DataElementValue(2,2);     //Measurement significance, coded
                            sValue = oSegment.get_DataElementValue(2,3);     //Measurement attribute identification
                            sValue = oSegment.get_DataElementValue(2,4);     //Measurement attribute
                            listBox1.Items.Add("Unit: " + oSegment.get_DataElementValue(3,1));     //Measure unit qualifier
                            listBox1.Items.Add("Weight: " + oSegment.get_DataElementValue(3,2));     //Measurement value
                            sValue = oSegment.get_DataElementValue(3,3);     //Range minimum
                            sValue = oSegment.get_DataElementValue(3,4);     //Range maximum
                            sValue = oSegment.get_DataElementValue(3,5);     //Significant digits
                        }   //SegmentID
                    }
                    else if (sLoopSection == "NAD")
                    {
                        if (sSegmentID == "NAD")
                        {
                            sNadPartyQlfr = oSegment.get_DataElementValue(1,0);     //Party qualifier
                        }   //SegmentID

                        if (sNadPartyQlfr == "CZ")
                        {
                            if (sSegmentID == "NAD")
                            {
                                listBox1.Items.Add("Consignor ID: " + oSegment.get_DataElementValue(2,1));     //Party identification
                                sValue = oSegment.get_DataElementValue(2,2);     //Code list qualifier
                                sValue = oSegment.get_DataElementValue(2,3);     //Code list responsible agency, coded
                                sValue = oSegment.get_DataElementValue(3,1);     //Name and address line
                                sValue = oSegment.get_DataElementValue(3,2);     //Name and address line
                                sValue = oSegment.get_DataElementValue(3,3);     //Name and address line
                                sValue = oSegment.get_DataElementValue(3,4);     //Name and address line
                                sValue = oSegment.get_DataElementValue(3,5);     //Name and address line
                                listBox1.Items.Add("Consignor Name: " + oSegment.get_DataElementValue(4,1));     //Party name
                                sValue = oSegment.get_DataElementValue(4,2);     //Party name
                                sValue = oSegment.get_DataElementValue(4,3);     //Party name
                                sValue = oSegment.get_DataElementValue(4,4);     //Party name
                                sValue = oSegment.get_DataElementValue(4,5);     //Party name
                                sValue = oSegment.get_DataElementValue(4,6);     //Party name format, coded
                            }   //SegmentID
                        }
                        else if (sNadPartyQlfr == "SE")
                        {
                            if (sSegmentID == "NAD")
                            {
                                listBox1.Items.Add("Seller ID: " + oSegment.get_DataElementValue(2,1));     //Party identification
                                sValue = oSegment.get_DataElementValue(2,2);     //Code list qualifier
                                sValue = oSegment.get_DataElementValue(2,3);     //Code list responsible agency, coded
                                sValue = oSegment.get_DataElementValue(3,1);     //Name and address line
                                sValue = oSegment.get_DataElementValue(3,2);     //Name and address line
                                sValue = oSegment.get_DataElementValue(3,3);     //Name and address line
                                sValue = oSegment.get_DataElementValue(3,4);     //Name and address line
                                sValue = oSegment.get_DataElementValue(3,5);     //Name and address line
                                listBox1.Items.Add("Seller Name: " + oSegment.get_DataElementValue(4,1));     //Party name
                                sValue = oSegment.get_DataElementValue(4,2);     //Party name
                                sValue = oSegment.get_DataElementValue(4,3);     //Party name
                                sValue = oSegment.get_DataElementValue(4,4);     //Party name
                                sValue = oSegment.get_DataElementValue(4,5);     //Party name
                                sValue = oSegment.get_DataElementValue(4,6);     //Party name format, coded
                            }   //SegmentID
                        }
                        else if (sNadPartyQlfr == "CA")
                        {
                            if (sSegmentID == "NAD")
                            {
                                listBox1.Items.Add("Carrier ID: " + oSegment.get_DataElementValue(2,1));     //Party identification
                                sValue = oSegment.get_DataElementValue(2,2);     //Code list qualifier
                                sValue = oSegment.get_DataElementValue(2,3);     //Code list responsible agency, coded
                                sValue = oSegment.get_DataElementValue(3,1);     //Name and address line
                                sValue = oSegment.get_DataElementValue(3,2);     //Name and address line
                                sValue = oSegment.get_DataElementValue(3,3);     //Name and address line
                                sValue = oSegment.get_DataElementValue(3,4);     //Name and address line
                                sValue = oSegment.get_DataElementValue(3,5);     //Name and address line
                                listBox1.Items.Add("Carrier Name: " + oSegment.get_DataElementValue(4,1));     //Party name
                                sValue = oSegment.get_DataElementValue(4,2);     //Party name
                                sValue = oSegment.get_DataElementValue(4,3);     //Party name
                                sValue = oSegment.get_DataElementValue(4,4);     //Party name
                                sValue = oSegment.get_DataElementValue(4,5);     //Party name
                                sValue = oSegment.get_DataElementValue(4,6);     //Party name format, coded
                            }   //SegmentID
                        }
                        else if (sNadPartyQlfr == "CN")
                        {
                            if (sSegmentID == "NAD")
                            {
                                listBox1.Items.Add("Consignee ID: " + oSegment.get_DataElementValue(2,1));     //Party identification
                                sValue = oSegment.get_DataElementValue(2,2);     //Code list qualifier
                                sValue = oSegment.get_DataElementValue(2,3);     //Code list responsible agency, coded
                                sValue = oSegment.get_DataElementValue(3,1);     //Name and address line
                                sValue = oSegment.get_DataElementValue(3,2);     //Name and address line
                                sValue = oSegment.get_DataElementValue(3,3);     //Name and address line
                                sValue = oSegment.get_DataElementValue(3,4);     //Name and address line
                                sValue = oSegment.get_DataElementValue(3,5);     //Name and address line
                                listBox1.Items.Add("Consignee Name: " + oSegment.get_DataElementValue(4,1));     //Party name
                                sValue = oSegment.get_DataElementValue(4,2);     //Party name
                                sValue = oSegment.get_DataElementValue(4,3);     //Party name
                                sValue = oSegment.get_DataElementValue(4,4);     //Party name
                                sValue = oSegment.get_DataElementValue(4,5);     //Party name
                                sValue = oSegment.get_DataElementValue(4,6);     //Party name format, coded
                            }   //SegmentID
                        }
                    }
                    else if (sLoopSection == "NAD;RFF")
                    {
                        if (sNadPartyQlfr == "SE")
                        {
                            if (sSegmentID == "RFF")
                            {
                                sValue = oSegment.get_DataElementValue(1,1);     //Reference qualifier
                                listBox1.Items.Add("Seller Account Number: " + oSegment.get_DataElementValue(1,2));     ////Reference number
                                sValue = oSegment.get_DataElementValue(1,3);     //Line number
                                sValue = oSegment.get_DataElementValue(1,4);     //Reference version number
                            }   //SegmentID
                        }
                        else if (sNadPartyQlfr == "CA")
                        {
                            if (sSegmentID == "RFF")
                            {
                                sValue = oSegment.get_DataElementValue(1,1);     //Reference qualifier
                                listBox1.Items.Add("Carrier Account Number: " + oSegment.get_DataElementValue(1,2));     ////Reference number
                                sValue = oSegment.get_DataElementValue(1,3);     //Line number
                                sValue = oSegment.get_DataElementValue(1,4);     //Reference version number
                            }   //SegmentID
                        }
                        else if (sNadPartyQlfr == "CN")
                        {
                            if (sSegmentID == "RFF")
                            {
                                sValue = oSegment.get_DataElementValue(1,1);     //Reference qualifier
                                listBox1.Items.Add("Consignee Account Number: " + oSegment.get_DataElementValue(1,2));     ////Reference number
                                sValue = oSegment.get_DataElementValue(1,3);     //Line number
                                sValue = oSegment.get_DataElementValue(1,4);     //Reference version number
                            }   //SegmentID
                        }
                    }
                    else if (sLoopSection == "TOD")
                    {
                        if (sSegmentID == "TOD")
                        {
                            sValue = oSegment.get_DataElementValue(1,0);     //Terms of delivery or transport function, coded
                            sValue = oSegment.get_DataElementValue(2,0);     //Transport charges method of payment, coded
                            sValue = oSegment.get_DataElementValue(3,1);     //Terms of delivery or transport, coded
                            sValue = oSegment.get_DataElementValue(3,2);     //Code list qualifier
                            sValue = oSegment.get_DataElementValue(3,3);     //Code list responsible agency, coded
                            sValue = oSegment.get_DataElementValue(3,4);     //Terms of delivery or transport
                            sValue = oSegment.get_DataElementValue(3,5);     //Terms of delivery or transport
                        }   //SegmentID
                    }
                    else if (sLoopSection == "TDT")
                    {
                        if (sSegmentID == "TDT")
                        {
                            sValue = oSegment.get_DataElementValue(1,0);     //Transport stage qualifier
                            sValue = oSegment.get_DataElementValue(2,0);     //Conveyance reference number
                            listBox1.Items.Add("Mode of Transport: " + oSegment.get_DataElementValue(3,1));     //Mode of transport, coded
                            sValue = oSegment.get_DataElementValue(3,2);     //Mode of transport
                            sValue = oSegment.get_DataElementValue(4,1);     //Type of means of transport identification
                            sValue = oSegment.get_DataElementValue(4,2);     //Type of means of transport
                            sValue = oSegment.get_DataElementValue(5,1);     //Carrier identification
                            sValue = oSegment.get_DataElementValue(5,2);     //Code list qualifier
                            sValue = oSegment.get_DataElementValue(5,3);     //Code list responsible agency, coded
                            sValue = oSegment.get_DataElementValue(5,4);     //Carrier name
                            sValue = oSegment.get_DataElementValue(6,0);     //Transit direction, coded
                            sValue = oSegment.get_DataElementValue(7,1);     //Excess transportation reason, coded
                            sValue = oSegment.get_DataElementValue(7,2);     //Excess transportation responsibility, coded
                            sValue = oSegment.get_DataElementValue(7,3);     //Customer authorization number
                            sValue = oSegment.get_DataElementValue(8,1);     //Id. of means of transport identification
                            sValue = oSegment.get_DataElementValue(8,2);     //Code list qualifier
                            sValue = oSegment.get_DataElementValue(8,3);     //Code list responsible agency, coded
                            sValue = oSegment.get_DataElementValue(8,4);     //Id. of the means of transport
                            sValue = oSegment.get_DataElementValue(8,5);     //Nationality of means of transport, coded
                        }   //SegmentID
                    }
                    else if (sLoopSection == "EQD")
                    {
                        if (sSegmentID == "EQD")
                        {
                            sValue = oSegment.get_DataElementValue(1,0);     //Equipment qualifier
                            listBox1.Items.Add("Equipment ID number: " + oSegment.get_DataElementValue(2,1));     //Equipment identification number
                            sValue = oSegment.get_DataElementValue(2,2);     //Code list qualifier
                            sValue = oSegment.get_DataElementValue(2,3);     //Code list responsible agency, coded
                            sValue = oSegment.get_DataElementValue(2,4);     //Country, coded
                        }   //sSegmentID
                    }   //sLoopSection
                }
                else if (nArea == 2)
                {
                    if (sLoopSection == "CPS")
                    {
                        if (sSegmentID == "CPS")
                        {
                            sValue = oSegment.get_DataElementValue(1,0);     //Hierarchical id. number
                            sValue = oSegment.get_DataElementValue(2,0);     //Hierarchical parent id.
                            sValue = oSegment.get_DataElementValue(3,0);     //Packaging level, coded
                        }   //SegmentID
                    }
                    else if (sLoopSection == "CPS;PAC")
                    {
                        if (sSegmentID == "PAC")
                        {
                            listBox1.Items.Add("Number of packages: " + oSegment.get_DataElementValue(1,0));     //Number of packages
                            sValue = oSegment.get_DataElementValue(2,1);     //Packaging level, coded
                            sValue = oSegment.get_DataElementValue(2,2);     //Packaging related information, coded
                            sValue = oSegment.get_DataElementValue(2,3);     //Packaging terms and conditions, coded
                            listBox1.Items.Add("Type of package ID: " + oSegment.get_DataElementValue(3,1));     //Type of packages identification
                            sValue = oSegment.get_DataElementValue(3,2);     //Code list qualifier
                            sValue = oSegment.get_DataElementValue(3,3);     //Code list responsible agency, coded
                            sValue = oSegment.get_DataElementValue(3,4);     //Type of packages
                        }
                        else if (sSegmentID == "QTY")
                        {
                            listBox1.Items.Add("Quantity per pack: " + oSegment.get_DataElementValue(1,1));     //Quantity qualifier
                            sValue = oSegment.get_DataElementValue(1,2);     //Quantity
                            sValue = oSegment.get_DataElementValue(1,3);     //Measure unit qualifier
                        }   //SegmentID
                    }
                    else if (sLoopSection == "CPS;PAC;PCI")
                    {
                        if (sSegmentID == "PCI")
                        {
                            sValue = oSegment.get_DataElementValue(1,0);     //Marking instructions, coded
                        }
                        else if (sSegmentID == "RFF")
                        {
                            if (oSegment.get_DataElementValue(1,1) == "AAT") //Reference qualifier
                            {
                                listBox1.Items.Add("Master label number: " + oSegment.get_DataElementValue(1,2));     //Reference number
                            }
                            sValue = oSegment.get_DataElementValue(1,3);     //Line number
                            sValue = oSegment.get_DataElementValue(1,4);     //Reference version number
                        }
                        else if (sSegmentID == "GIR")
                        {
                            sValue = oSegment.get_DataElementValue(1,0);     //Reference version number
                            if (oSegment.get_DataElementValue(2,2) == "ML")     //Identity number qualifier
                            {
                                listBox1.Items.Add("Label number: " + oSegment.get_DataElementValue(2,1));     //Identity number
                            }
                            sValue = oSegment.get_DataElementValue(2,3);     //Status, coded
                        }   //SegmentID
                    }
                    else if (sLoopSection == "CPS;LIN")
                    {
                        if (sSegmentID == "LIN")
                        {
                            listBox1.Items.Add("Line item number: " + oSegment.get_DataElementValue(1,0));     //Line item number
                            sValue = oSegment.get_DataElementValue(2,0);     //Action request/notification, coded
                            if (oSegment.get_DataElementValue(3,2) == "IN" )     //Item number type, coded
                            {
                                listBox1.Items.Add("Buyer Item number: " + oSegment.get_DataElementValue(3,1));     //Item number
                            }
                            sValue = oSegment.get_DataElementValue(3,3);     //Code list qualifier
                            sValue = oSegment.get_DataElementValue(3,4);     //Code list responsible agency, coded
                        }
                        else if (sSegmentID == "PIA")
                        {
                            sValue = oSegment.get_DataElementValue(1,0);     //Code list responsible agency, coded
                            if (oSegment.get_DataElementValue(2,2) == "SA")     //Item number type, coded
                            {
                                listBox1.Items.Add("Supplier's article number: " + oSegment.get_DataElementValue(2,1));     //Item number
                            }
                            sValue = oSegment.get_DataElementValue(2,3);     //Code list qualifier
                            sValue = oSegment.get_DataElementValue(2,4);     //Code list responsible agency, coded
                        }
                        else if (sSegmentID == "IMD")
                        {
                            sValue = oSegment.get_DataElementValue(1,0);     //Code list responsible agency, coded
                            sValue = oSegment.get_DataElementValue(2,0);     //Code list responsible agency, coded
                            sValue = oSegment.get_DataElementValue(3,1);     //Item description identification
                            sValue = oSegment.get_DataElementValue(3,2);     //Code list qualifier
                            sValue = oSegment.get_DataElementValue(3,3);     //Code list responsible agency, coded
                            listBox1.Items.Add("Item Description: " + oSegment.get_DataElementValue(3,4));     //Item description
                            sValue = oSegment.get_DataElementValue(3,5);     //Item description
                            sValue = oSegment.get_DataElementValue(3,6);     //Language, coded
                        }
                        else if (sSegmentID == "QTY")
                        {
                            sValue = oSegment.get_DataElementValue(1,1);     //Quantity qualifier
                            listBox1.Items.Add("Despatch quantity: " + oSegment.get_DataElementValue(1,2));     //Quantity
                            sValue = oSegment.get_DataElementValue(1,3);     //Measure unit qualifier
                        }   //SegmentID
                    }
                    else if (sLoopSection == "CPS;LIN;RFF")
                    {
                        if (sSegmentID == "RFF")
                        {
                            sValue = oSegment.get_DataElementValue(1,1);     //Reference qualifier
                            listBox1.Items.Add("Order number: " + oSegment.get_DataElementValue(1,2));     //Reference number
                            sValue = oSegment.get_DataElementValue(1,3);     //Line number
                            sValue = oSegment.get_DataElementValue(1,4);     //Reference version number
                        }
                        else if (sSegmentID == "DTM")
                        {
                            if (oSegment.get_DataElementValue(1,1) == "4")     //Date/time/period qualifier
                            {
                                listBox1.Items.Add("Order date: " + oSegment.get_DataElementValue(1,2));     //Date/time/period
                            }
                            sValue = oSegment.get_DataElementValue(1,3);     //Date/time/period format qualifier
                        }   //sSegmentID
                    }   //sLoopSection
                }
                else if (nArea == 3)
                {
                    if (sLoopSection == "")
                    {
                    }   //sLoopSection
                }   //nArea
 
                //GETS THE NEXT DATA SEGMENT
                ediDataSegment.Set(ref oSegment, (ediDataSegment) oSegment.Next()); //oSegment = (ediDataSegment) oSegment.Next();
 
            } 

            MessageBox.Show("done");

        }
    

    Click here to download a trial version of the Framework EDI