private void btnTranslate_Click(object sender, EventArgs e)
        {
            ediDocument oEdiDoc;
            ediSchema oSchema;
            ediSchemas oSchemas;
            ediDataSegment oSegment;
            string sSegmentID = "";
            string sValue = "";
            string sLoopDesc = "";
            string sEdiFileName = "";
            string sSefFileName = "";
            int nArea = 0;
            int nPos = 0;
            string sQlfr = "";
            string sPath = AppDomain.CurrentDomain.BaseDirectory;

            // Create the top-level application object "ediDocument". 
            oEdiDoc = new ediDocument();

            // For UN/EDIFACT documents, specify the terminators, indicators,  and separators 
            // because it does not automatically detect from the document.  If there is 
            // a UNA Service Segment, which specifies the delimiters then these steps 
            // are not necessary. 
            oEdiDoc.SegmentTerminator = "'{13:10}";
            oEdiDoc.ElementTerminator = "+";
            oEdiDoc.CompositeTerminator = ":";
            oEdiDoc.ReleaseIndicator = "?";

            // This makes certain that Framework EDI only uses the SEF file provided, 
            // and that it does not use its built-in Standard Reference table to translate 
            // the EDI document 
            oSchemas = (ediSchemas) oEdiDoc.GetSchemas();
            oSchemas.EnableStandardReference = false;

            // The FORWARD-ONLY cursor increases the performance of processing the EDI 
            // document (see Technical Note 3 below). 
            oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardOnly;
            sEdiFileName = sPath + "BAPLIE_D95B_SAMPLE.edi";
            sSefFileName = sPath + "BAPLIE_D95B.EVAL0.SEF";

            // Specify SEF file to load. 
            oSchema = (ediSchema) oEdiDoc.LoadSchema(sSefFileName, SchemaTypeIDConstants.Schema_Standard_Exchange_Format);


            // Specify EDI document to read. 
            oEdiDoc.LoadEdi(sEdiFileName);

            // Gets the first data segment in the EDI document. 
            oSegment = (ediDataSegment) oEdiDoc.FirstDataSegment;

            // Loop that will traverse through the EDI document from top to bottom. This 
            // is required for FORWARD-ONLY cursor. 
            while (oSegment != null)
            {

                // Data segments are uniquely identified by their segment Identifier (ID). 
                // The loop section and the area (or table) properties of the data segment 
                // are read for each iteration of the loop.  
                sSegmentID = oSegment.ID;
                sLoopDesc = oSegment.LoopSection;
                nArea = oSegment.Area;
                nPos = oSegment.Position;

                if (nArea == 0)
                {

                    // Data segments that are not designated an area (i.e. area = 0)  
                    // are control segments that are part of the Interchange or  
                    // Functional Group envelopes, and are not part of the Message. 

                    if (sSegmentID == "UNB")
                    {
                        // Syntax identifier (S001) 
                        sValue = oSegment.get_DataElementValue(1, 1);         // Syntax identifier (0001) 
                        sValue = oSegment.get_DataElementValue(1, 2);         // Syntax version number (0002) 
                        sValue = oSegment.get_DataElementValue(2, 1);         // Interchange sender identification (0004) 
                        listBox1.Items.Add("Interchange sender id: " + sValue);
                        sValue = oSegment.get_DataElementValue(2, 2);         // Partner identification code qualifier (0007) 
                        sValue = oSegment.get_DataElementValue(2, 3);         // Interchange sender internal identification (0008) 
                        sValue = oSegment.get_DataElementValue(3, 1);         // Recipient identification (0010) 
                        listBox1.Items.Add("Recipient id: " + sValue);
                        sValue = oSegment.get_DataElementValue(3, 2);         // Partner identification code qualifier (0007) 
                        sValue = oSegment.get_DataElementValue(3, 3);         // Routing address (0014) 
                        sValue = oSegment.get_DataElementValue(4, 1);         // Date (0017) 
                        listBox1.Items.Add("Interchange Date: " + sValue);
                        sValue = oSegment.get_DataElementValue(4, 2);         // Time (0019) 
                        sValue = oSegment.get_DataElementValue(5, 0);         // Interchange control reference (0020) 
                        listBox1.Items.Add("Interchange Control No:" + sValue);
                        sValue = oSegment.get_DataElementValue(6, 1);         // Recipient reference/password (0022) 
                        sValue = oSegment.get_DataElementValue(6, 2);         // Recipient's reference/password qualifier (0025) 
                        sValue = oSegment.get_DataElementValue(7, 0);         // Application reference (0026) 
                        sValue = oSegment.get_DataElementValue(8, 0);         // Processing priority code (0029) 
                        sValue = oSegment.get_DataElementValue(9, 0);         // Acknowledgement request (0031) 
                        sValue = oSegment.get_DataElementValue(10, 0);         // Interchange Agreement Identifier (0032) 
                        sValue = oSegment.get_DataElementValue(11, 0);         // Test indicator (0035) 
                        

                    }
                    else if (sSegmentID == "UNZ")
                    {
                        sValue = oSegment.get_DataElementValue(1, 0);         // Interchange control count (0036) 
                        sValue = oSegment.get_DataElementValue(2, 0);         // Interchange control reference (0020) 

                    }

                }
                else if (nArea == 1)
                {

                    // Data segments in area 1 are processed here. 

                    if (sLoopDesc == "")
                    {

                        if (sSegmentID == "UNH")         // Message header 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Message reference number (0062) 
                            listBox1.Items.Add("Message Reference No: " + sValue);
                            sValue = oSegment.get_DataElementValue(2, 1);         // Message type identifier (0065) 
                            sValue = oSegment.get_DataElementValue(2, 2);         // Message version number (0052) 
                            sValue = oSegment.get_DataElementValue(2, 3);         // Message release number (0054) 
                            sValue = oSegment.get_DataElementValue(2, 4);         // Controlling agency (0051) 
                            sValue = oSegment.get_DataElementValue(2, 5);         // Association assigned code (0057) 
                        }
                        else if (sSegmentID == "BGM")         // Beginning of message 
                        {
                            sValue = oSegment.get_DataElementValue(1, 1);         // Document/message name, coded (1001) 
                            sValue = oSegment.get_DataElementValue(1, 2);         // Code list qualifier (1131) 
                            sValue = oSegment.get_DataElementValue(1, 3);         // Code list responsible agency, coded (3055) 
                            sValue = oSegment.get_DataElementValue(1, 4);         // Document/message name (1000) 
                            sValue = oSegment.get_DataElementValue(2, 0);         // Document/message number (1004) 
                            listBox1.Items.Add("Document number: " + sValue);
                            sValue = oSegment.get_DataElementValue(3, 0);         // Message function, coded (1225) 
                        }
                        else if (sSegmentID == "DTM")         // Date/time/period 
                        {
                            sQlfr = oSegment.get_DataElementValue(1, 1);         // Date/time/period qualifier (2005) 
                            if (sQlfr == "137")
                            {
                                sValue = oSegment.get_DataElementValue(1, 2);         // Date/time/period (2380) 
                                listBox1.Items.Add("Document Date: " + sValue);
                                sValue = oSegment.get_DataElementValue(1, 3);         // Date/time/period format qualifier (2379) 

                            }
                           
                        }

                    }
                    else if (sLoopDesc == "TDT")
                    {

                        if (sSegmentID == "TDT")         // Transport information 
                            {
                                sValue = oSegment.get_DataElementValue(1, 0);         // Transport stage qualifier (8051) 
                                sValue = oSegment.get_DataElementValue(2, 0);         // Conveyance reference number (8028) 
                                listBox1.Items.Add("Conveyance reference number: " + sValue);
                                sValue = oSegment.get_DataElementValue(5, 1);         // Carrier identification (3127) 
                                sValue = oSegment.get_DataElementValue(5, 2);         // Code list qualifier (1131) 
                                sValue = oSegment.get_DataElementValue(5, 3);         // Code list responsible agency, coded (3055) 
                                sValue = oSegment.get_DataElementValue(8, 1);         // Id. of means of transport identification (8213) 
                                sValue = oSegment.get_DataElementValue(8, 2);         // Code list qualifier (1131) 
                                sValue = oSegment.get_DataElementValue(8, 3);         // Code list responsible agency, coded (3055) 
                                sValue = oSegment.get_DataElementValue(8, 4);         // Id. of the means of transport (8212) 
                                sValue = oSegment.get_DataElementValue(8, 5);         // Nationality of means of transport, coded (8453) 
                            }
                            else if (sSegmentID == "LOC")         // Place/location identification 
                            {
                                sQlfr = oSegment.get_DataElementValue(1, 0);         // Place/location qualifier (3227) 
                                if (sQlfr == "5")   //Place of departure
                                {
                                    sValue = oSegment.get_DataElementValue(2, 1);         // Place/location identification (3225) 
                                    listBox1.Items.Add("Place of Departure: " + sValue);
                                    sValue = oSegment.get_DataElementValue(2, 2);         // Code list qualifier (1131) 
                                    sValue = oSegment.get_DataElementValue(2, 3);         // Code list responsible agency, coded (3055) 
                                    sValue = oSegment.get_DataElementValue(2, 4);         // Place/location (3224) 
                                }
                                else if (sQlfr == "61")   //Place of departure
                                {
                                    sValue = oSegment.get_DataElementValue(2, 1);         // Place/location identification (3225) 
                                    listBox1.Items.Add("Next Port of call: " + sValue);
                                    sValue = oSegment.get_DataElementValue(2, 2);         // Code list qualifier (1131) 
                                    sValue = oSegment.get_DataElementValue(2, 3);         // Code list responsible agency, coded (3055) 
                                    sValue = oSegment.get_DataElementValue(2, 4);         // Place/location (3224) 
                                }
                                
                            }
                            else if (sSegmentID == "DTM")         // Date/time/period 
                            {
                                sQlfr  = oSegment.get_DataElementValue(1, 1);         // Date/time/period qualifier (2005) 
                                if (sQlfr == "178")
                                {
                                    sValue = oSegment.get_DataElementValue(1, 2);         // Date/time/period (2380) 
                                    listBox1.Items.Add("Arrival Date: " + sValue);
                                    sValue = oSegment.get_DataElementValue(1, 3);         // Date/time/period format qualifier (2379) 
                                }
                                
                            }

                    }
                    else if (sLoopDesc == "LOC")
                    {

                        if (sSegmentID == "LOC" && nPos == 130)         // NOTE: Position number had to identify this LOC segment from the other LOC segment in the same group
                        {
                            sQlfr  = oSegment.get_DataElementValue(1, 0);         // Place/location qualifier (3227) 
                            if (sQlfr == "147") //Stowage cell
                            {
                                sValue = oSegment.get_DataElementValue(2, 1);         // Place/location identification (3225) 
                                listBox1.Items.Add("Stowage cell " + sValue);
                                sValue = oSegment.get_DataElementValue(2, 2);         // Code list qualifier (1131) 
                                sValue = oSegment.get_DataElementValue(2, 3);         // Code list responsible agency, coded (3055) 
                                sValue = oSegment.get_DataElementValue(2, 4);         // Place/location (3224) 
                            }
                            
                        }
                        else if (sSegmentID == "GID")         // Goods item details 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Goods item number (1496) 
                            sValue = oSegment.get_DataElementValue(2, 1);         // Number of packages (7224) 
                            sValue = oSegment.get_DataElementValue(2, 2);         // Type of packages identification (7065) 

                        }
                        else if (sSegmentID == "GDS")         // Nature of cargo 
                        {
                            sValue = oSegment.get_DataElementValue(1, 1);         // Nature of cargo, coded (7085) 
                            sValue = oSegment.get_DataElementValue(1, 2);         // Code list qualifier (1131) 
                            sValue = oSegment.get_DataElementValue(1, 3);         // Code list responsible agency, coded (3055) 

                        }
                        else if (sSegmentID == "FTX")         // Free text 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Text subject qualifier (4451)
                            sValue = oSegment.get_DataElementValue(4, 1);         // Free text (4440) 
                            sValue = oSegment.get_DataElementValue(4, 2);         // Free text (4440) 
                            sValue = oSegment.get_DataElementValue(4, 3);         // Free text (4440) 
                            sValue = oSegment.get_DataElementValue(4, 4);         // Free text (4440) 
                            sValue = oSegment.get_DataElementValue(4, 5);         // Free text (4440) 
                        }
                        else if (sSegmentID == "MEA")         // Measurements 
                        {
                            sQlfr = oSegment.get_DataElementValue(1, 0);         // Measurement purpose qualifier (6311) 
                            if (sQlfr == "WT")  //Weights
                            {
                                sValue = oSegment.get_DataElementValue(3, 1);         // Measure unit qualifier (6411) 
                                sValue = oSegment.get_DataElementValue(3, 2);         // Measurement value (6314) 
                                listBox1.Items.Add("Weight value: " + sValue);
                            }
                            
                        }
                        else if (sSegmentID == "DIM")         // Dimensions 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Dimension qualifier (6145) 
                            sValue = oSegment.get_DataElementValue(2, 1);         // Measure unit qualifier (6411) 
                            sValue = oSegment.get_DataElementValue(2, 2);         // Length dimension (6168) 
                            sValue = oSegment.get_DataElementValue(2, 3);         // Width dimension (6140) 
                            sValue = oSegment.get_DataElementValue(2, 4);         // Height dimension (6008) 

                        }
                        else if (sSegmentID == "TMP")         // Temperature 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Temperature qualifier (6245) 
                            sValue = oSegment.get_DataElementValue(2, 1);         // Temperature setting (6246) 
                            sValue = oSegment.get_DataElementValue(2, 2);         // Measure unit qualifier (6411) 

                        }
                        else if (sSegmentID == "RNG")         // Range details 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Range type qualifier (6167) 
                            sValue = oSegment.get_DataElementValue(2, 1);         // Measure unit qualifier (6411) 
                            sValue = oSegment.get_DataElementValue(2, 2);         // Range minimum (6162) 
                            sValue = oSegment.get_DataElementValue(2, 3);         // Range maximum (6152) 

                        }
                        else if (sSegmentID == "LOC" && nPos == 210)         // Place/location identification 
                        {
                            sQlfr = oSegment.get_DataElementValue(1, 0);         // Place/location qualifier (3227) 
                            if (sQlfr == "9")
                            {
                                sValue = oSegment.get_DataElementValue(2, 1);         // Place/location identification (3225) 
                                listBox1.Items.Add("Place of Loading: " + sValue);
                                sValue = oSegment.get_DataElementValue(2, 2);         // Code list qualifier (1131) 
                                sValue = oSegment.get_DataElementValue(2, 3);         // Code list responsible agency, coded (3055) 
                            }
                            else if (sQlfr == "11")
                            {
                                sValue = oSegment.get_DataElementValue(2, 1);         // Place/location identification (3225) 
                                listBox1.Items.Add("Place of Discharge: " + sValue);
                                sValue = oSegment.get_DataElementValue(2, 2);         // Code list qualifier (1131) 
                                sValue = oSegment.get_DataElementValue(2, 3);         // Code list responsible agency, coded (3055) 
                            }
                            else if (sQlfr == "83")
                            {
                                sValue = oSegment.get_DataElementValue(2, 1);         // Place/location identification (3225) 
                                listBox1.Items.Add("Placce of Delivery: " + sValue);
                                sValue = oSegment.get_DataElementValue(2, 2);         // Code list qualifier (1131) 
                                sValue = oSegment.get_DataElementValue(2, 3);         // Code list responsible agency, coded (3055) 
                            }
                        }
                        else if (sSegmentID == "RFF")         // Reference 
                        {
                            sValue = oSegment.get_DataElementValue(1, 1);         // Reference qualifier (1153) 
                            sValue = oSegment.get_DataElementValue(1, 2);         // Reference number (1154) 
                            listBox1.Items.Add("Bill of Lading: " + sValue);

                        }         // sSegmentID == "RFF" 


                    }
                    else if (sLoopDesc == "LOC;EQD")
                    {

                        if (sSegmentID == "EQD")         // Equipment details 
                        {
                            sQlfr = oSegment.get_DataElementValue(1, 0);         // Equipment qualifier (8053) 
                            if (sQlfr == "CN")  //Container
                            {
                                sValue = oSegment.get_DataElementValue(2, 1);         // Equipment identification number (8260) 
                                listBox1.Items.Add("Container ID: " + sValue);
                                sValue = oSegment.get_DataElementValue(3, 1);         // Equipment size and type identification (8155) 
                                sValue = oSegment.get_DataElementValue(5, 0);         // Equipment status, coded (8249) 
                                sValue = oSegment.get_DataElementValue(6, 0);         // Full/empty indicator, coded (8169) 
                            }
                            
                        }
                        else if (sSegmentID == "EQA")         // Attached equipment 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Equipment qualifier (8053) 
                            sValue = oSegment.get_DataElementValue(2, 1);         // Equipment identification number (8260) 
                            sValue = oSegment.get_DataElementValue(2, 2);         // Code list qualifier (1131) 
                            sValue = oSegment.get_DataElementValue(2, 3);         // Code list responsible agency, coded (3055) 
                            sValue = oSegment.get_DataElementValue(2, 4);         // Country, coded (3207) 

                        }
                        else if (sSegmentID == "NAD")         // Name and address 
                        {
                            sQlfr = oSegment.get_DataElementValue(1, 0);         // Party qualifier (3035) 
                            if (sQlfr == "")
                            {
                                sValue = oSegment.get_DataElementValue(2, 1);         // Party identification (3039) 
                                listBox1.Items.Add("Carrier ID:" + sValue);
                                sValue = oSegment.get_DataElementValue(2, 2);         // Code list qualifier (1131) 
                                sValue = oSegment.get_DataElementValue(2, 3);         // Code list responsible agency, coded (3055) 
                            }

                        }         // sSegmentID == "NAD" 

                    }
                    else if (sLoopDesc == "LOC;DGS")
                    {

                        if (sSegmentID == "DGS")         // Dangerous goods 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Dangerous goods regulations, coded (8273) 
                            listBox1.Items.Add("Dangerous goods code:" + sValue);
                            sValue = oSegment.get_DataElementValue(2, 1);         // Hazard code identification (8351) 
                            sValue = oSegment.get_DataElementValue(2, 2);         // Hazard substance/item/page number (8078) 
                            sValue = oSegment.get_DataElementValue(3, 1);         // UNDG number (7124) 
                            sValue = oSegment.get_DataElementValue(4, 1);         // Shipment flashpoint (7106) 
                            sValue = oSegment.get_DataElementValue(4, 2);         // Measure unit qualifier (6411) 
                            sValue = oSegment.get_DataElementValue(5, 0);         // Packing group, coded (8339) 
                            sValue = oSegment.get_DataElementValue(6, 0);         // EMS number (8364) 
                            sValue = oSegment.get_DataElementValue(7, 0);         // MFAG (8410) 
                            sValue = oSegment.get_DataElementValue(9, 1);         // Hazard identification number, upper part (8158) 
                            sValue = oSegment.get_DataElementValue(9, 2);         // Substance identification number, lower part (8186) 
                            sValue = oSegment.get_DataElementValue(10, 1);         // Dangerous goods label marking (8246) 
                            sValue = oSegment.get_DataElementValue(10, 2);         // Dangerous goods label marking (8246) 
                            sValue = oSegment.get_DataElementValue(10, 3);         // Dangerous goods label marking (8246) 
                        }
                        else if (sSegmentID == "FTX")         // Free text 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Text subject qualifier (4451) 
                            sValue = oSegment.get_DataElementValue(4, 1);         // Free text (4440) 
                            sValue = oSegment.get_DataElementValue(4, 2);         // Free text (4440) 
                            sValue = oSegment.get_DataElementValue(4, 3);         // Free text (4440) 
                            sValue = oSegment.get_DataElementValue(4, 4);         // Free text (4440) 
                            sValue = oSegment.get_DataElementValue(4, 5);         // Free text (4440) 
                        }         // sSegmentID == "FTX" 

                    }         // sLoopDesc == "LOC;DGS" 

                }         // nArea == 1 

                // Get the next data segment in the document. 
                ediDataSegment.Set(ref oSegment, oSegment.Next());

            }         // oSegment != null 
        }
    

    Click here to download a trial version of the Framework EDI