private void btnGenerate_Click(object sender, System.EventArgs e)
        {
            //This is just an example program to demonstrate how to generate and validate an 810 EDI file 
            //in C# using the Framework EDI component

            ediDocument oEdiDoc = null;
            ediSchema oSchema = null;
            ediSchemas oSchemas = null;
            ediInterchange oInterchange = null;
            ediGroup oGroup = null;
            ediTransactionSet oTransactionset = null;
            ediDataSegment oSegment = null;
            ediWarnings oWarnings = null;
            ediWarning oWarning = null;

            int nErrors;
            string sPath;
            string sEdiFile;
            string sSefFile;

            sPath = AppDomain.CurrentDomain.BaseDirectory;

            sSefFile = "810_X12-4010.SEF";
            sEdiFile = "810OUTPUT.X12";
 
            //CREATES OEDIDOC 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;
 
            //ENABLES FORWARD WRITE, AND INCREASES BUFFER I/O TO IMPROVE PERFORMANCE
            oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardWrite;
            oEdiDoc.set_Property(DocumentPropertyIDConstants.Property_DocumentBufferIO, 2000);
 
            //SET TERMINATORS
            oEdiDoc.SegmentTerminator = "~{13:10}";
            oEdiDoc.ElementTerminator = "*";
            oEdiDoc.CompositeTerminator = ">";
 
            //LOADS THE SEF FILE
            ediSchema.Set(ref oSchema, (ediSchema) oEdiDoc.LoadSchema(sPath + sSefFile, 0));
 
            //CREATES THE ISA SEGMENT
            ediInterchange.Set(ref oInterchange, (ediInterchange) oEdiDoc.CreateInterchange("X","004010"));
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oInterchange.GetDataSegmentHeader());
            oSegment.set_DataElementValue(1,0,"00");     //Authorization Information Qualifier
            oSegment.set_DataElementValue(2,0,"          ");     //Authorization Information
            oSegment.set_DataElementValue(3,0,"00");     //Security Information Qualifier
            oSegment.set_DataElementValue(4,0,"          ");     //Security Information
            oSegment.set_DataElementValue(5,0,"ZZ");     //Interchange ID Qualifier
            oSegment.set_DataElementValue(6,0,"SENDERISA      ");     //Interchange Sender ID
            oSegment.set_DataElementValue(7,0,"ZZ");     //Interchange ID Qualifier
            oSegment.set_DataElementValue(8,0,"RECEIVERISA    ");     //Interchange Receiver ID
            oSegment.set_DataElementValue(9,0,"960807");     //Interchange Date
            oSegment.set_DataElementValue(10,0,"1548");     //Interchange Time
            oSegment.set_DataElementValue(11,0,"U");     //Interchange Control Standards Identifier
            oSegment.set_DataElementValue(12,0,"00401");     //Interchange Control Version Number
            oSegment.set_DataElementValue(13,0,"000000020");     //Interchange Control Number
            oSegment.set_DataElementValue(14,0,"0");     //Acknowledgment Requested
            oSegment.set_DataElementValue(15,0,"T");     //Usage Indicator
            oSegment.set_DataElementValue(16,0,">");     //Component Element Separator
 
            //CREATES THE GS SEGMENT
            ediGroup.Set(ref oGroup, (ediGroup) oInterchange.CreateGroup("004010"));
            ediDataSegment.Set( ref oSegment, (ediDataSegment) oGroup.GetDataSegmentHeader());
            oSegment.set_DataElementValue(1,0,"IN");     //Functional Identifier Code
            oSegment.set_DataElementValue(2,0,"SENDERDEPT");     //Application Sender's Code
            oSegment.set_DataElementValue(3,0,"007326879");     //Application Receiver's Code
            oSegment.set_DataElementValue(4,0,"19960807");     //Date
            oSegment.set_DataElementValue(5,0,"1548");     //Time
            oSegment.set_DataElementValue(6,0,"1");     //Group Control Number
            oSegment.set_DataElementValue(7,0,"X");     //Responsible Agency Code
            oSegment.set_DataElementValue(8,0,"004010");     //Version / Release / Industry Identifier Code
 
            //CREATES THE ST SEGMENT
            ediTransactionSet.Set(ref oTransactionset, (ediTransactionSet) oGroup.CreateTransactionSet("810"));
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.GetDataSegmentHeader());
            oSegment.set_DataElementValue(1,0,"810");     //Transaction Set Identifier Code
            oSegment.set_DataElementValue(2,0,"000000001");     //Transaction Set Control Number
 
            //BIG - BEGINNING SEGMENT FOR INVOICE
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("BIG"));
            //oSegment.set_DataElementValue(1,0,"19971211");     //Date        //this is a mandatory element, which will generata an error if omitted
            oSegment.set_DataElementValue(2,0,txtInvoiceNo.Text );     //Invoice Number
            oSegment.set_DataElementValue(4,0,"A99999-01");     //Purchase Order Number
 
            //SHIP-TO INFORMATION LOOP
            //N1 - NAME
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1\\N1"));
            oSegment.set_DataElementValue(1,0,"ST");     //Entity Identifier Code
            oSegment.set_DataElementValue(2,0,"BUYSNACKS PORT");     //Name
            oSegment.set_DataElementValue(3,0,"9");     //Identification Code Qualifier
            oSegment.set_DataElementValue(4,0,"1223334445");     //Identification Code
 
            //N3 - ADDRESS INFORMATION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1\\N3"));
            oSegment.set_DataElementValue(1,0,"1000 N. SAMPLE HIGHWAY");     //Address Information
 
            //N4 - GEOGRAPHIC LOCATION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1\\N4"));
            oSegment.set_DataElementValue(1,0,"ATHENS");     //City Name
            oSegment.set_DataElementValue(2,0,"GA");     //State or Province Code
            oSegment.set_DataElementValue(3,0,"30603");     //Postal Code
 
            //BILL-TO INFORMATION LOOP
            //N1 - NAME
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(2)\\N1"));    //it is not necessary to include the instance loop counter e.g. (2) when the cursor type is set to forwardwrite
            oSegment.set_DataElementValue(1,0,"BT");     //Entity Identifier Code
            oSegment.set_DataElementValue(2,0,"BUYSNACKS");     //Name
            oSegment.set_DataElementValue(3,0,"9");     //Identification Code Qualifier
            oSegment.set_DataElementValue(4,0,"1223334444");     //Identification Code
 
            //N3 - ADDRESS INFORMATION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(2)\\N3"));
            oSegment.set_DataElementValue(1,0,"P.O. BOX 0000");     //Address Information
 
            //N4 - GEOGRAPHIC LOCATION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(2)\\N4"));
            oSegment.set_DataElementValue(1,0,"TEMPLE");     //City Name
            oSegment.set_DataElementValue(2,0,"TX");     //State or Province Code
            oSegment.set_DataElementValue(3,0,"76503");     //Postal Code
 
            //REMIT-TO INFORMATION
            //N1 - NAME
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(3)\\N1"));
            oSegment.set_DataElementValue(1,0,"RE");     //Entity Identifier Code
            oSegment.set_DataElementValue(2,0,"FOODSELLER");     //Name
            oSegment.set_DataElementValue(3,0,"9");     //Identification Code Qualifier
            oSegment.set_DataElementValue(4,0,"12345QQQQ");     //Identification Code
 
            //N3 - ADDRESS INFORMATION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(3)\\N3"));
            oSegment.set_DataElementValue(1,0,"P.O. BOX 222222");     //Address Information
 
            //N4 - GEOGRAPHIC LOCATION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(3)\\N4"));
            oSegment.set_DataElementValue(1,0,"DALLAS");     //City Name
            oSegment.set_DataElementValue(2,0,"TX");     //State or Province Code
            oSegment.set_DataElementValue(3,0,"723224444");     //Postal Code
 
            //ITD - TERMS OF SALE/DEFERRED TERMS OF SALE
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("ITD"));
            oSegment.set_DataElementValue(1,0,"01");     //Terms Type Code
            oSegment.set_DataElementValue(2,0,"3");     //Terms Basis Date Code
            oSegment.set_DataElementValue(3,0,"1.000");     //Terms Discount Percent
            oSegment.set_DataElementValue(5,0,"15");     //Terms Discount Days Due
            oSegment.set_DataElementValue(7,0,"16");     //Terms Net Days
            oSegment.set_DataElementValue(12,0,"1/15 NET 30");     //Description
 
            //FOB - F.O.B. RELATED INSTRUCTIONS
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("FOB"));
            oSegment.set_DataElementValue(1,0,"PP");     //Shipment Method of Payment
 
            //IT1 - BASELINE ITEM DATA (INVOICE)
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IT1\\IT1"));
            oSegment.set_DataElementValue(2,0,"16");     //Quantity Invoiced
            oSegment.set_DataElementValue(3,0,"CA");     //Unit or Basis for Measurement Code
            oSegment.set_DataElementValue(4,0,"12.34");     //Unit Price
            oSegment.set_DataElementValue(6,0,"UA");     //Product/Service ID Qualifier
            oSegment.set_DataElementValue(7,0,"002840022222");     //Product/Service ID
 
            //PID - PRODUCT/ITEM DESCRIPTION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IT1\\PID\\PID"));
            oSegment.set_DataElementValue(1,0,"F");     //Item Description Type
            oSegment.set_DataElementValue(5,0,"CRUNCHY CHIPS LSS");     //Description
 
            //IT1 - BASELINE ITEM DATA (INVOICE)
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IT1(2)\\IT1"));
            oSegment.set_DataElementValue(2,0,"13");     //Quantity Invoiced
            oSegment.set_DataElementValue(3,0,"CA");     //Unit or Basis for Measurement Code
            oSegment.set_DataElementValue(4,0,"12.34");     //Unit Price
            oSegment.set_DataElementValue(6,0,"UA");     //Product/Service ID Qualifier
            oSegment.set_DataElementValue(7,0,"002840033333");     //Product/Service ID
 
            //PID - PRODUCT/ITEM DESCRIPTION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IT1(2)\\PID\\PID"));
            oSegment.set_DataElementValue(1,0,"F");     //Item Description Type
            oSegment.set_DataElementValue(5,0,"NACHO CHIPS LSS");     //Description
 
            //IT1 - BASELINE ITEM DATA (INVOICE)
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IT1(3)\\IT1"));
            oSegment.set_DataElementValue(2,0,"32");     //Quantity Invoiced
            oSegment.set_DataElementValue(3,0,"CA");     //Unit or Basis for Measurement Code
            oSegment.set_DataElementValue(4,0,"12.34");     //Unit Price
            oSegment.set_DataElementValue(6,0,"UA");     //Product/Service ID Qualifier
            oSegment.set_DataElementValue(7,0,"002840044444");     //Product/Service ID
 
            //PID - PRODUCT/ITEM DESCRIPTION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IT1(3)\\PID\\PID"));
            oSegment.set_DataElementValue(1,0,"F");     //Item Description Type
            oSegment.set_DataElementValue(5,0,"POTATO CHIPS");     //Description
 
            //IT1 - BASELINE ITEM DATA (INVOICE)
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IT1(4)\\IT1"));
            oSegment.set_DataElementValue(2,0,"51");     //Quantity Invoiced
            oSegment.set_DataElementValue(3,0,"CA");     //Unit or Basis for Measurement Code
            oSegment.set_DataElementValue(4,0,"12.34");     //Unit Price
            oSegment.set_DataElementValue(6,0,"UA");     //Product/Service ID Qualifier
            oSegment.set_DataElementValue(7,0,"002840055555");     //Product/Service ID
 
            //PID - PRODUCT/ITEM DESCRIPTION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IT1(4)\\PID\\PID"));
            oSegment.set_DataElementValue(1,0,"F");     //Item Description Type
            oSegment.set_DataElementValue(5,0,"CORN CHIPS");     //Description
 
            //IT1 - BASELINE ITEM DATA (INVOICE)
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IT1(5)\\IT1"));
            oSegment.set_DataElementValue(2,0,"9");     //Quantity Invoiced
            oSegment.set_DataElementValue(3,0,"CA");     //Unit or Basis for Measurement Code
            oSegment.set_DataElementValue(4,0,"12.34");     //Unit Price
            oSegment.set_DataElementValue(6,0,"UA");     //Product/Service ID Qualifier
            oSegment.set_DataElementValue(7,0,"002840066666");     //Product/Service ID
 
            //PID - PRODUCT/ITEM DESCRIPTION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IT1(5)\\PID\\PID"));
            oSegment.set_DataElementValue(1,0,"F");     //Item Description Type
            oSegment.set_DataElementValue(5,0,"BBQ CHIPS");     //Description
 
            //IT1 - BASELINE ITEM DATA (INVOICE)
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IT1(6)\\IT1"));
            oSegment.set_DataElementValue(2,0,"85");     //Quantity Invoiced
            oSegment.set_DataElementValue(3,0,"CA");     //Unit or Basis for Measurement Code
            oSegment.set_DataElementValue(4,0,"12.34");     //Unit Price
            oSegment.set_DataElementValue(6,0,"UA");     //Product/Service ID Qualifier
            oSegment.set_DataElementValue(7,0,"002840077777");     //Product/Service ID
 
            //PID - PRODUCT/ITEM DESCRIPTION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IT1(6)\\PID\\PID"));
            oSegment.set_DataElementValue(1,0,"F");     //Item Description Type
            oSegment.set_DataElementValue(5,0,"GREAT BIG CHIPS LSS");     //Description
 
            //IT1 - BASELINE ITEM DATA (INVOICE)
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IT1(7)\\IT1"));
            oSegment.set_DataElementValue(2,0,"1");     //Quantity Invoiced
            oSegment.set_DataElementValue(3,0,"CA");     //Unit or Basis for Measurement Code
            oSegment.set_DataElementValue(4,0,"12.34");     //Unit Price
            oSegment.set_DataElementValue(6,0,"UA");     //Product/Service ID Qualifier
            oSegment.set_DataElementValue(7,0,"002840088888");     //Product/Service ID
 
            //PID - PRODUCT/ITEM DESCRIPTION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IT1(7)\\PID\\PID"));
            oSegment.set_DataElementValue(1,0,"F");     //Item Description Type
            oSegment.set_DataElementValue(5,0,"MINI CHIPS LSS");     //Description
 
            //TDS - TOTAL MONETARY VALUE SUMMARY
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("TDS"));
            oSegment.set_DataElementValue(1,0,"255438");     //Amount
 
            //CAD - CARRIER DETAIL
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CAD"));
            oSegment.set_DataElementValue(5,0,"FREEFORM");     //Routing
 
            //ISS - INVOICE SHIPMENT SUMMARY
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("ISS\\ISS"));
            oSegment.set_DataElementValue(1,0,"207");     //Number of Units Shipped
            oSegment.set_DataElementValue(2,0,"CA");     //Unit or Basis for Measurement Code
 
            //CTT - TRANSACTION TOTALS
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CTT"));
            oSegment.set_DataElementValue(1,0,"7");     //Number of Line Items
 
            //TRAILING SEGMENTS ARE AUTOMATICALLY CREATED WHEN FREDI COMMITS (SAVES)
            //THE EDIDOC OBJECT INTO AN EDI FILE.
            oEdiDoc.Save(sPath + sEdiFile);
 
            //check to see if any errors were found during generation
            ediWarnings.Set(ref oWarnings, (ediWarnings) oEdiDoc.GetWarnings());
            nErrors = oWarnings.Count;
            for (int i=1; i <= nErrors; i++)
            {
                ediWarning.Set(ref oWarning, (ediWarning) oWarnings.get_Warning(i));
                listBoxErrors.Items.Add(oWarning.Description);
            }

            //DESTROYS OBJECTS
            oSegment.Dispose();
            oTransactionset.Dispose();
            oGroup.Dispose();
            oInterchange.Dispose();
            oSchema.Dispose();
            oSchemas.Dispose();
            oEdiDoc.Dispose();

            MessageBox.Show("Done. Output = " + sPath + sEdiFile);        }
    

    Click here to download a trial version of the Framework EDI