private void btnTranslate_Click(object sender, System.EventArgs e)
        {
            // This is just an example program to show how to translate a HIPAA 270 4010 X092 EDI X12 file and
            // at the same time create a Functional Acknowledgment 997 in C# with the Framework EDI component.

            ediDocument oEdiDoc = null;
            ediDataSegment oSegment = null;
            ediAcknowledgment oAck = null;
            ediSchemas oSchemas = null;

            string sSegmentID;
            string sLoopSection;
            int nArea;
            string sHLcode = "";
            string sValue = "";

            btnTranslate.Enabled = false;


            ediDocument.Set(ref oEdiDoc, new ediDocument());    // oEdiDoc = new ediDocument();


            // Disabling the internal standard reference library to makes sure that 
            // FREDI uses only the SEF file provided
            ediSchemas.Set(ref oSchemas,(ediSchemas) oEdiDoc.GetSchemas());    //oSchemas = (ediSchemas) oEdiDoc.GetSchemas();
            oSchemas.EnableStandardReference = false;

            // This makes certain that the EDI file must use the same version SEF file, otherwise
            // the process will stop.
            oSchemas.set_Option(SchemasOptionIDConstants.OptSchemas_VersionRestrict,1);

            // By setting the cursor type to ForwardOnly, FREDI does not load the entire file into memory, which
            // improves performance when processing larger EDI files.
            oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardOnly;

            // If an acknowledgment file has to be generated, an acknowledgment object must be created, and its 
            // property must be enabled before loading the EDI file.
            oAck = (ediAcknowledgment) oEdiDoc.GetAcknowledgment();
            oAck.EnableFunctionalAcknowledgment = true;

            // Set the starting point of the control numbers in the acknowledgment
            oAck.set_Property(AcknowledgmentPropertyIDConstants.PropertyAck_StartInterchangeControlNum,1001);
            oAck.set_Property(AcknowledgmentPropertyIDConstants.PropertyAck_StartGroupControlNum,1);
            oAck.set_Property(AcknowledgmentPropertyIDConstants.PropertyAck_StartTransactionSetControlNum,1);

            // Error codes that are not automatically mapped to an acknowlegment error number by FREDI can be set by
            // using the MapDataElementLevelError method.
            oAck.MapDataElementLevelError(13209, 5,"","","","");

            // All SEF files required for processing the EDI files must be provided by calling the LoadSchema.  
            // The "LoadSchema" method does not actually load the SEF files at this time, but are actually 
            // loaded during the LoadEdi method.
            oEdiDoc.LoadSchema("270_X092.SEF", 0);    //for EDI (810) file
            oEdiDoc.LoadSchema("997_X12-4010.SEF", 0);    //for Ack (997) file

            // Loads EDI file and the corresponding SEF file
            oEdiDoc.LoadEdi("270.X12");

            // Gets the first data segment in the EDI files
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oEdiDoc.FirstDataSegment);  //oSegment = (ediDataSegment) oEdiDoc.FirstDataSegment

            // This loop iterates though the EDI file a segment at a time
            while ( oSegment != null ) 
            {
                // A segment is identified by its Area number, Loop section and segment id.
                sSegmentID = oSegment.ID;
                sLoopSection = oSegment.LoopSection;
                nArea = oSegment.Area;

                if (nArea == 0) 
                {
                    if (sLoopSection == "") 
                    {
                        if (sSegmentID == "ISA") 
                        {
                            // map data elements of ISA segment in here
                        }
                        else if (sSegmentID == "GS") 
                        {
                            // map data elements of GS segment in here
                        }
                    }
                }
                else if (nArea == 1) 
                {
                    if (sLoopSection == "") 
                    {
                        if (sSegmentID == "ST") 
                        {
                            // map data element of ST segment in here
                            // sValue  = oSegment.get_DataElementValue(2,0);
                        }
                        else if (sSegmentID == "BHT")
                        {
                            // mapping the data elements of BIG segment to textbox fields
                            txtReferenceID.Text = oSegment.get_DataElementValue(3,0);
                            txtTransactionDate.Text = oSegment.get_DataElementValue(4,0);
                        }
                    }    // sLoopSection == ""
                }    // nArea == 1
                else if (nArea == 2) 
                {
                    if (sLoopSection == "HL" && sSegmentID == "HL") 
                    {
                        // The Hierarchical Level Code of the loop is obtained first to determine the topic 
                        // of the loop
                        sHLcode = oSegment.get_DataElementValue(3,0);
                    }
                    

                    if (sHLcode == "20") 
                    {        //Information Source
                        if (sLoopSection == "HL")
                        {
                            if (sSegmentID == "HL") 
                            {
                            }
                        }    
                        else if (sLoopSection =="HL;NM1")
                        {
                            if (sSegmentID == "NM1")
                            {
                                txtPayerLastname.Text = oSegment.get_DataElementValue(3,0);
                                txtPayerFirstname.Text = oSegment.get_DataElementValue(4,0);
                                txtPayerId.Text = oSegment.get_DataElementValue(9,0);
                            }    //sSegmentID
                        }    //sLoopSection
                    }    // sHLcode == "20"

                    else if (sHLcode == "21") 
                    {        //Information Receiver
                        if (sLoopSection == "HL")
                        {
                            if (sSegmentID == "HL") 
                            {
                            }
                        }    
                        else if (sLoopSection =="HL;NM1")
                        {
                            if (sSegmentID == "NM1")
                            {
                                txtProviderLastname.Text = oSegment.get_DataElementValue(3,0);
                                txtProviderFirstname.Text = oSegment.get_DataElementValue(4,0);
                                txtProviderNo.Text = oSegment.get_DataElementValue(9,0);
                            }
                            else if (sSegmentID == "REF")
                            {
                                // txtProviderNetId.Text = oSegment.get_DataElementValue(2,0);
                            }
                            else if (sSegmentID == "N3") 
                            {
                                // txtProviderAddress.Text  = oSegment.get_DataElementValue(1,0);    //Ship-To Address
                            }
                            else if (sSegmentID == "N4") 
                            {
                                // txtProviderCity.Text = oSegment.get_DataElementValue(1,0);    //Ship-To City
                                // txtProviderState.Text  = oSegment.get_DataElementValue(2,0);    // Ship-To State
                                // txtProviderZip.Text = oSegment.get_DataElementValue(3,0);
                            }    //sSegmentID
                            else if (sSegmentID == "PER") 
                            {
                            }
                            else if (sSegmentID == "PER") 
                            {
                            }    //sSegmentID
                        }    //sLoopSection
                    }    // sHLcode == "21"

                    else if (sHLcode == "22") 
                    {        //Subscriber
                        if (sLoopSection == "HL")
                        {
                            if (sSegmentID == "HL") 
                            {
                            }
                            else if (sSegmentID == "TRN")
                            {
                                txtSubscriberId.Text = oSegment.get_DataElementValue(2,0);
                                txtSubscriberCompanyId.Text = oSegment.get_DataElementValue(3,0);
                            }
                        }    
                        else if (sLoopSection =="HL;NM1")
                        {
                            if (sSegmentID == "NM1")
                            {
                                txtInsuredLastname.Text = oSegment.get_DataElementValue(3,0);
                                txtInsuredFirstname.Text = oSegment.get_DataElementValue(4,0);
                                txtInsuredMidInitial.Text = oSegment.get_DataElementValue(5,0);
                            }
                            else if (sSegmentID == "REF")
                            {
                                txtPolicyNo.Text = oSegment.get_DataElementValue(2,0);
                            }
                            else if (sSegmentID == "N3") 
                            {
                                txtInsuredAddress.Text  = oSegment.get_DataElementValue(1,0);    //Ship-To Address
                            }
                            else if (sSegmentID == "N4") 
                            {
                                txtInsuredCity.Text = oSegment.get_DataElementValue(1,0);    //Ship-To City
                                txtInsuredState.Text  = oSegment.get_DataElementValue(2,0);    // Ship-To State
                                txtInsuredZip.Text = oSegment.get_DataElementValue(3,0);
                            }    //sSegmentID
                        }
                        else if (sLoopSection =="HL;EQ")
                        {
                            if (sSegmentID == "EQ")
                            {
                            }
                            else if (sSegmentID == "AMT")
                            {
                            }
                            else if (sSegmentID == "III")
                            {
                            }
                            else if (sSegmentID == "REF")
                            {
                            }
                            else if (sSegmentID == "DTP")
                            {
                            }
                        }    //sLoopSection
                    }    //sHLcode == "22"

                    else if (sHLcode == "23") 
                    {        //Dependent
                        if (sLoopSection == "HL")
                        {
                            if (sSegmentID == "HL") 
                            {
                            }
                            else if (sSegmentID == "TRN")
                            {
                            }
                        }    
                        else if (sLoopSection =="HL;NM1")
                        {
                            if (sSegmentID == "NM1")
                            {
                                // txtDependentLastname.Text = oSegment.get_DataElementValue(3,0);
                                // txtDependentFirstname.Text = oSegment.get_DataElementValue(4,0);
                                // txtDependentMidInitial.Text = oSegment.get_DataElementValue(5,0);
                            }
                            else if (sSegmentID == "REF")
                            {
                            }
                            else if (sSegmentID == "N3") 
                            {
                                // txtDependentAddress.Text  = oSegment.get_DataElementValue(1,0);    //Ship-To Address
                            }
                            else if (sSegmentID == "N4") 
                            {
                                // txtDependentCity.Text = oSegment.get_DataElementValue(1,0);    //Ship-To City
                                // txtDependentState.Text  = oSegment.get_DataElementValue(2,0);    // Ship-To State
                                // txtDependentZip.Text = oSegment.get_DataElementValue(3,0);
                            }    //sSegmentID
                        }
                        else if (sLoopSection =="HL;EQ")
                        {
                            if (sSegmentID == "EQ")
                            {
                            }
                            else if (sSegmentID == "AMT")
                            {
                            }
                            else if (sSegmentID == "III")
                            {
                            }
                            else if (sSegmentID == "REF")
                            {
                            }
                            else if (sSegmentID == "DTP")
                            {
                            }
                        }//sLoopSection
                    }//sHLcode == "23"
                }// nArea == 2
                else if (nArea == 3) 
                {    
                    // segments belonging in the summary section are read here
                }// nArea == 3

                ediDataSegment.Set(ref oSegment, (ediDataSegment) oSegment.Next());    //oSegment = (ediDataSegment) oSegment.Next();
            }


            // Checks the 997 acknowledgment file just created.
            // The 997 file is an EDI file, so the logic to read the 997 Functional Acknowledgemnt file is similar
            // to translating any other EDI file.

            // Gets the first segment of the 997 acknowledgment file
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oAck.GetFirst997DataSegment());    //oSegment = (ediDataSegment) oAck.GetFirst997DataSegment();

            while ( oSegment != null ) 
            {
                nArea = oSegment.Area;
                sLoopSection = oSegment.LoopSection;
                sSegmentID = oSegment.ID;

                if (nArea == 1)
                {
                    if (sLoopSection == "")
                    {
                        if (sSegmentID == "AK9")
                        {
                            if (oSegment.get_DataElementValue(1,0) == "R")
                            {
                                // reject EDI file
                            }
                        }
                    }    // sLoopSection == ""
                }    //nArea == 1
                ediDataSegment.Set(ref oSegment, (ediDataSegment) oSegment.Next());    //oSegment = (ediDataSegment) oSegment.Next();
            }    //oSegment != null

            //save the acknowledgment
            oAck.Save("997_270.X12");
        }
    }

    Click here to download a trial version of the Framework EDI