private void btnTranslate_Click(object sender, System.EventArgs e)
        {
            // This is just an example program to demnstrate how to translate an EDI 856 file 
            // in C# using the Framework EDI component

            ediDocument oEdiDoc = null;
            ediSchemas oSchemas = null;
            ediDataSegment oSegment = null;
            string sSegmentID;
            string sLoopSection;
            int nArea;
            string sValue;
            string sHlEntity = "";
            string sNm1Entity = "";
            string sQlfr = "";

            Cursor = Cursors.WaitCursor;

            string sPath = AppDomain.CurrentDomain.BaseDirectory;
            string sEdiFile = "856_4010.X12";
            string sSefFile = "856_X12-4010.SEF";
 
            //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 TRANSLATE THE EDI FILE.
            ediSchemas.Set(ref oSchemas,(ediSchemas) oEdiDoc.GetSchemas());  //oSchemas = (ediSchemas) oEdiDoc.GetSchemas();
            oSchemas.EnableStandardReference = false;
 
            //THIS OPTIONS STOPS FREDI FROM KEEPING ALL THE SEGMENTS IN MEMORY.  IMPROVES PERFORMANCE
            oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardOnly;
 
            //LOADS THE SEF FILE
            oEdiDoc.ImportSchema(sPath + sSefFile, 0);
 
            //LOADS THE EDI FILE
            oEdiDoc.LoadEdi(sPath + sEdiFile);
 
            //GETS THE FIRST DATA SEGMENT
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oEdiDoc.FirstDataSegment);  //oSegment = (ediDataSegment) oEdiDoc.FirstDataSegment
 
            //LOOP THAT WILL TRAVERSE THRU EDI FILE FROM TOP TO BOTTOM
            while ( oSegment != null )
            {
                //DATA SEGMENTS ARE 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 == "ISA")
                        {
                            sValue = oSegment.get_DataElementValue(1,0);     //Authorization Information Qualifier
                            sValue = oSegment.get_DataElementValue(2,0);     //Authorization Information
                            sValue = oSegment.get_DataElementValue(3,0);     //Security Information Qualifier
                            sValue = oSegment.get_DataElementValue(4,0);     //Security Information
                            sValue = oSegment.get_DataElementValue(5,0);     //Interchange ID Qualifier
                            sValue = oSegment.get_DataElementValue(6,0);     //Interchange Sender ID
                            sValue = oSegment.get_DataElementValue(7,0);     //Interchange ID Qualifier
                            sValue = oSegment.get_DataElementValue(8,0);     //Interchange Receiver ID
                            sValue = oSegment.get_DataElementValue(9,0);     //Interchange Date
                            sValue = oSegment.get_DataElementValue(10,0);     //Interchange Time
                            sValue = oSegment.get_DataElementValue(11,0);     //Interchange Control Standards Identifier
                            sValue = oSegment.get_DataElementValue(12,0);     //Interchange Control Version Number
                            listBox1.Items.Add(oSegment.get_DataElement(13).Description + " = " +  oSegment.get_DataElementValue(13,0));     //Interchange Control Number
                            sValue = oSegment.get_DataElementValue(14,0);     //Acknowledgment Requested
                            sValue = oSegment.get_DataElementValue(15,0);     //Usage Indicator
                            sValue = oSegment.get_DataElementValue(16,0);     //Component Element Separator
                        }
                        else if (sSegmentID == "GS")
                        {
                            sValue = oSegment.get_DataElementValue(1,0);     //Functional Identifier Code
                            sValue = oSegment.get_DataElementValue(2,0);     //Application Sender's Code
                            sValue = oSegment.get_DataElementValue(3,0);     //Application Receiver's Code
                            sValue = oSegment.get_DataElementValue(4,0);     //Date
                            sValue = oSegment.get_DataElementValue(5,0);     //Time
                            listBox1.Items.Add(oSegment.get_DataElement(6).Description + " = " +  oSegment.get_DataElementValue(6,0));     //Group Control Number
                            sValue = oSegment.get_DataElementValue(7,0);     //Responsible Agency Code
                            sValue = oSegment.get_DataElementValue(8,0);     //Version / Release / Industry Identifier Code
                        }   //sSegmentID
                    }    //sLoopSection
                }
                else if (nArea == 1)
                {
                    if (sLoopSection == "")
                    {
                        if (sSegmentID == "ST")
                        {
                            sValue = oSegment.get_DataElementValue(1,0);     //Transaction Set Identifier Code
                            listBox1.Items.Add(oSegment.get_DataElement(2).Description + " = " +  oSegment.get_DataElementValue(2,0));;     //Transaction Set Control Number
                        }
                        else if (sSegmentID == "BSN")
                        {
                            sValue = oSegment.get_DataElementValue(1,0);     //Transaction Set Purpose Code
                            listBox1.Items.Add(oSegment.get_DataElement(2).Description + " = " +  oSegment.get_DataElementValue(2,0));;     //Shipment Identification
                            sValue = oSegment.get_DataElementValue(3,0);     //Date
                            sValue = oSegment.get_DataElementValue(4,0);     //Time
                            sValue = oSegment.get_DataElementValue(5,0);     //Hierarchical Structure Code
                        }   //sSegmentID
                    }    //sLoopSection
                }
                else if (nArea == 2)
                {
                    if (sLoopSection == "HL")
                    {
                        if (sSegmentID == "HL")
                        {
                           sHlEntity = oSegment.get_DataElementValue(3,0);   //In most cases the loop qualifier is the first element of the first segment in the loop, but not necessarily
                        }
                        if (sHlEntity == "S") //SHIPMENT
                        {
                            if (sSegmentID == "HL")
                            {
                                sValue = oSegment.get_DataElementValue(1,0);     //Hierarchical ID Number
                                sValue = oSegment.get_DataElementValue(2,0);     //Hierarchical Parent ID Number
                                sValue = oSegment.get_DataElementValue(3,0);     //Hierarchical Level Code
                                sValue = oSegment.get_DataElementValue(4,0);     //Hierarchical Child Code
                            }
                            else if (sSegmentID == "TD1")
                            {
                                listBox1.Items.Add(oSegment.get_DataElement(1).Description + " = " +  oSegment.get_DataElementValue(1,0));     //Packaging Code
                                listBox1.Items.Add(oSegment.get_DataElement(2).Description + " = " +  oSegment.get_DataElementValue(2,0));     //Lading Quantity
                                sValue = oSegment.get_DataElementValue(3,0);     //Commodity Code Qualifier
                                sValue = oSegment.get_DataElementValue(4,0);     //Commodity Code
                                sValue = oSegment.get_DataElementValue(5,0);     //Lading Description
                                sValue = oSegment.get_DataElementValue(6,0);     //Weight Qualifier
                                sValue = oSegment.get_DataElementValue(7,0);     //Weight
                                sValue = oSegment.get_DataElementValue(8,0);     //Unit or Basis for Measurement Code
                            }
                            else if (sSegmentID == "TD5")
                            {
                                sValue = oSegment.get_DataElementValue(1,0);     //Routing Sequence Code
                                sValue = oSegment.get_DataElementValue(2,0);     //Identification Code Qualifier
                                sValue = oSegment.get_DataElementValue(3,0);     //Identification Code
                                sValue = oSegment.get_DataElementValue(4,0);     //Transportation Method/Type Code
                                sValue = oSegment.get_DataElementValue(5,0);     //Routing
                            }
                            else if (sSegmentID == "TD3")
                            {
                                sValue = oSegment.get_DataElementValue(1,0);     //Equipment Description Code
                                sValue = oSegment.get_DataElementValue(2,0);     //Equipment Initial
                                sValue = oSegment.get_DataElementValue(3,0);     //Equipment Number
                            }
                            else if (sSegmentID == "REF")
                            {
                                sValue = oSegment.get_DataElementValue(1,0);     //Reference Identification Qualifier
                                listBox1.Items.Add(oSegment.get_DataElement(2).Description + " = " +  oSegment.get_DataElementValue(2,0));     //Reference Identification
                            }
                            else if (sSegmentID == "DTM")
                            {
                                sQlfr = oSegment.get_DataElementValue(1,0);     //Date/Time Qualifier

                                if (sQlfr == "011")    //shipped date
                                {
                                    listBox1.Items.Add(oSegment.get_DataElement(2).Description + " = " +  oSegment.get_DataElementValue(2,0));     //Date
                                }
                                else if (sQlfr == "017")    //estimated delivery date
                                {
                                    listBox1.Items.Add(oSegment.get_DataElement(2).Description + " = " +  oSegment.get_DataElementValue(2,0));     //Date
                                }
                            }   //Segment ID
                        }
                        else if (sLoopSection == "HL;N1")
                        {
                            if (sSegmentID == "N1")
                            {
                                sNm1Entity = oSegment.get_DataElementValue(1,0);
                            }
                            if (sNm1Entity == "BT")        //BILL-TO
                            {
                                if (sSegmentID == "N1")
                                {
                                    sValue = oSegment.get_DataElementValue(1,0);     //Entity Identifier Code
                                    listBox1.Items.Add(oSegment.get_DataElement(2).Description + " Bill-To = " +  oSegment.get_DataElementValue(2,0));     //Name
                                    sValue = oSegment.get_DataElementValue(3,0);     //Identification Code Qualifier
                                    sValue = oSegment.get_DataElementValue(4,0);     //Identification Code
                                }
                                else if (sSegmentID == "N3")
                                {
                                    sValue = oSegment.get_DataElementValue(1,0);     //Address Information
                                }
                                else if (sSegmentID == "N4")
                                {
                                    sValue = oSegment.get_DataElementValue(1,0);     //City Name
                                    sValue = oSegment.get_DataElementValue(2,0);     //State or Province Code
                                    sValue = oSegment.get_DataElementValue(3,0);     //Postal Code
                                }   //sSegmentID
                            }
                            else if (sNm1Entity == "ST")    //SHIP-TO 
                            {
                                if (sSegmentID == "N1")
                                {
                                    sValue = oSegment.get_DataElementValue(1,0);     //Entity Identifier Code
                                    listBox1.Items.Add(oSegment.get_DataElement(2).Description + " Ship-To = " +  oSegment.get_DataElementValue(2,0));     //Name
                                    sValue = oSegment.get_DataElementValue(3,0);     //Identification Code Qualifier
                                    sValue = oSegment.get_DataElementValue(4,0);     //Identification Code
                                }
                                else if (sSegmentID == "N3")
                                {
                                    sValue = oSegment.get_DataElementValue(1,0);     //Address Information
                                }
                                else if (sSegmentID == "N4")
                                {
                                    sValue = oSegment.get_DataElementValue(1,0);     //City Name
                                    sValue = oSegment.get_DataElementValue(2,0);     //State or Province Code
                                    sValue = oSegment.get_DataElementValue(3,0);     //Postal Code
                                }   //sSegmentID
                            }    //sNm1Entity
                        }//shipment
                        else if (sHlEntity == "O") //ORDER
                        {
                            if (sSegmentID == "HL")
                            {
                                sValue = oSegment.get_DataElementValue(1,0);     //Hierarchical ID Number
                                sValue = oSegment.get_DataElementValue(2,0);     //Hierarchical Parent ID Number
                                sValue = oSegment.get_DataElementValue(3,0);     //Hierarchical Level Code
                                sValue = oSegment.get_DataElementValue(4,0);     //Hierarchical Child Code
                            }
                            else if (sSegmentID == "PRF")
                            {
                                listBox1.Items.Add(oSegment.get_DataElement(1).Description + " = " +  oSegment.get_DataElementValue(1,0));     
                                sValue = oSegment.get_DataElementValue(2,0);     
                                sValue = oSegment.get_DataElementValue(3,0);     
                                sValue = oSegment.get_DataElementValue(4,0);     
                            }
                            else if (sSegmentID == "REF")
                            {
                                sValue = oSegment.get_DataElementValue(1,0);     //Reference Identification Qualifier
                                listBox1.Items.Add(oSegment.get_DataElement(2).Description + " = " +  oSegment.get_DataElementValue(2,0));     //Reference Identification
                            }
                            else if (sSegmentID == "FOB")
                            {
                                sValue = oSegment.get_DataElementValue(1,0);     
                                sValue = oSegment.get_DataElementValue(2,0);     
                            }

                        }//order
                        else if (sHlEntity == "I") //ITEMS
                        {
                            if (sSegmentID == "HL")
                            {
                                sValue = oSegment.get_DataElementValue(1,0);     //Hierarchical ID Number
                                sValue = oSegment.get_DataElementValue(2,0);     //Hierarchical Parent ID Number
                                sValue = oSegment.get_DataElementValue(3,0);     //Hierarchical Level Code
                                sValue = oSegment.get_DataElementValue(4,0);     //Hierarchical Child Code
                            }
                            else if (sSegmentID == "LIN")
                            {
                                listBox1.Items.Add(oSegment.get_DataElement(1).Description + " = " +  oSegment.get_DataElementValue(1,0));    
                                sValue = oSegment.get_DataElementValue(2,0);     
                                listBox1.Items.Add(oSegment.get_DataElement(3).Description + " = " +  oSegment.get_DataElementValue(3,0));     
                            }
                            else if (sSegmentID == "SN1")
                            {
                                sValue = oSegment.get_DataElementValue(1,0);     
                                listBox1.Items.Add(oSegment.get_DataElement(2).Description + " = " +  oSegment.get_DataElementValue(2,0));     
                                sValue = oSegment.get_DataElementValue(3,0);     
                                sValue = oSegment.get_DataElementValue(4,0);     
                                listBox1.Items.Add(oSegment.get_DataElement(5).Description + " = " +  oSegment.get_DataElementValue(5,0));     
                                sValue = oSegment.get_DataElementValue(6,0);     
                                sValue = oSegment.get_DataElementValue(7,0);     
                                sValue = oSegment.get_DataElementValue(8,0);     
                            }
                            else if (sSegmentID == "PRF")
                            {
                                sValue = oSegment.get_DataElementValue(1,0);     
                                sValue = oSegment.get_DataElementValue(2,0);     
                                sValue = oSegment.get_DataElementValue(3,0);     
                                sValue = oSegment.get_DataElementValue(4,0);     
                            }
                            else if (sSegmentID == "PID")
                            {
                                sValue = oSegment.get_DataElementValue(1,0);     
                                sValue = oSegment.get_DataElementValue(2,0);     
                                sValue = oSegment.get_DataElementValue(3,0);     
                                sValue = oSegment.get_DataElementValue(4,0);     
                                listBox1.Items.Add(oSegment.get_DataElement(5).Description + " = " +  oSegment.get_DataElementValue(5,0));
                            }    //sSegmentID
                        }    //items
                    }    //sLoopSection
                }
                else if (nArea == 3)
                {
                    if (sLoopSection == "")
                    {
                        if (sSegmentID == "CTT")
                        {
                            sValue = oSegment.get_DataElementValue(1,0);     //Number of Line Items
                        }   //sSegmentID
                    }   //sLoopSection
                }   //nArea
 
                //GETS THE NEXT DATA SEGMENT
                ediDataSegment.Set(ref oSegment, (ediDataSegment) oSegment.Next());  //oSegment = (ediDataSegment) oSegment.Next();
 
            }   //while

            Cursor = Cursors.Default;
            MessageBox.Show("Done");
        
        }
    

    Click here to download a trial version of the Framework EDI