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

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

            string sPath = AppDomain.CurrentDomain.BaseDirectory;
            string sEdiFile = "211Output.X12";
            string sSefFile = "211_003070.SEF";
 
            //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","003070"));
            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,"AABB           ");     //Interchange Sender ID
            oSegment.set_DataElementValue(7,0,"01");     //Interchange ID Qualifier
            oSegment.set_DataElementValue(8,0,"112233445      ");     //Interchange Receiver ID
            oSegment.set_DataElementValue(9,0,"080304");     //Interchange Date
            oSegment.set_DataElementValue(10,0,"1116");     //Interchange Time
            oSegment.set_DataElementValue(11,0,"U");     //Interchange Control Standards Identifier
            oSegment.set_DataElementValue(12,0,"00307");     //Interchange Control Version Number
            oSegment.set_DataElementValue(13,0,"000017859");     //Interchange Control Number
            oSegment.set_DataElementValue(14,0,"0");     //Acknowledgment Requested
            oSegment.set_DataElementValue(15,0,"P");     //Usage Indicator
            oSegment.set_DataElementValue(16,0,">");     //Component Element Separator
 
            //CREATES THE GS SEGMENT
            ediGroup.Set(ref oGroup, (ediGroup) oInterchange.CreateGroup("003070"));
            ediDataSegment.Set( ref oSegment, (ediDataSegment) oGroup.GetDataSegmentHeader());
            oSegment.set_DataElementValue(1,0,"BL");     //Functional Identifier Code
            oSegment.set_DataElementValue(2,0,"AABB");     //Application Sender's Code
            oSegment.set_DataElementValue(3,0,"112233445");     //Application Receiver's Code
            oSegment.set_DataElementValue(4,0,"080304");     //Date
            oSegment.set_DataElementValue(5,0,"1116");     //Time
            oSegment.set_DataElementValue(6,0,"1");     //Group Control Number
            oSegment.set_DataElementValue(7,0,"X");     //Responsible Agency Code
            oSegment.set_DataElementValue(8,0,"003070");     //Version / Release / Industry Identifier Code
 
            //CREATES THE ST SEGMENT
            ediTransactionSet.Set(ref oTransactionset, (ediTransactionSet) oGroup.CreateTransactionSet("211"));
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.GetDataSegmentHeader());
            oSegment.set_DataElementValue(1,0,"211");     //Transaction Set Identifier Code
            oSegment.set_DataElementValue(2,0,"000010001");     //Transaction Set Control Number
 
            //BOL - BEGINNING SEGMENT FOR THE MOTOR CARRIER BILL OF LADING
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("BOL"));
            oSegment.set_DataElementValue(1,0,"SCAC");     //Standard Carrier Alpha Code
            oSegment.set_DataElementValue(2,0,"PP");     //Shipment Method of Payment
            oSegment.set_DataElementValue(3,0,"12345");     //Shipment Identification Number
            oSegment.set_DataElementValue(4,0,"990501");     //Date
            oSegment.set_DataElementValue(6,0,"1231234561");     //Reference Identification
 
            //B2A - SET PURPOSE
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("B2A"));
            oSegment.set_DataElementValue(1,0,"00");     //Transaction Set Purpose Code
 
            //MS2 - EQUIPMENT OR CONTAINER OWNER AND TYPE
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("MS2"));
            oSegment.set_DataElementValue(1,0,"SCAC");     //Standard Carrier Alpha Code
            oSegment.set_DataElementValue(2,0,"123456");     //Equipment Number
 
            //SHIPPER INFO LOOP
            //N1 - NAME
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1\\N1"));
            oSegment.set_DataElementValue(1,0,"SH");     //Entity Identifier Code
            oSegment.set_DataElementValue(2,0,"SHIPPER NAME");     //Name
            oSegment.set_DataElementValue(3,0,"93");     //Identification Code Qualifier
            oSegment.set_DataElementValue(4,0,"123456789");     //Identification Code
 
            //N3 - ADDRESS INFORMATION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1\\N3"));
            oSegment.set_DataElementValue(1,0,"9999 SHIPPER STREET");     //Address Information
            oSegment.set_DataElementValue(2,0,"ADDITIONAL ADDRESS LINE");     //Address Information
 
            //N4 - GEOGRAPHIC LOCATION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1\\N4"));
            oSegment.set_DataElementValue(1,0,"SHIPPER CITY");     //City Name
            oSegment.set_DataElementValue(2,0,"ST");     //State or Province Code
            oSegment.set_DataElementValue(3,0,"00000");     //Postal Code
 
            //CONSIGNEE INFO LOOP
            //N1 - NAME
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(2)\\N1"));
            oSegment.set_DataElementValue(1,0,"CN");     //Entity Identifier Code
            oSegment.set_DataElementValue(2,0,"CONSIGNEE NAME");     //Name
 
            //N3 - ADDRESS INFORMATION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(2)\\N3"));
            oSegment.set_DataElementValue(1,0,"9999 CONSIGNEE STREET");     //Address Information
            oSegment.set_DataElementValue(2,0,"ADDITIONAL ADDRESS LINE");     //Address Information
 
            //N4 - GEOGRAPHIC LOCATION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(2)\\N4"));
            oSegment.set_DataElementValue(1,0,"CONSIGNEE CITY");     //City Name
            oSegment.set_DataElementValue(2,0,"ST");     //State or Province Code
            oSegment.set_DataElementValue(3,0,"99999");     //Postal Code
 
            //G61 - CONTACT
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(2)\\G61"));
            oSegment.set_DataElementValue(1,0,"DC");     //Contact Function Code
            oSegment.set_DataElementValue(2,0,"DELIVERY CONTACT NAME");     //Name
            oSegment.set_DataElementValue(3,0,"TE");     //Communication Number Qualifier
            oSegment.set_DataElementValue(4,0,"5559999999");     //Communication Number
 
            //AT1 - BILL OF LADING LINE ITEM NUMBER
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("AT1\\AT1"));
            oSegment.set_DataElementValue(1,0,"1");     //Lading Line Item Number
 
            //L11 - BUSINESS INSTRUCTIONS AND REFERENCE NUMBER
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("AT1\\L11"));
            oSegment.set_DataElementValue(1,0,"999");     //Reference Identification
            oSegment.set_DataElementValue(2,0,"AE");     //Reference Identification Qualifier
 
            //AT4 - BILL OF LADING DESCRIPTION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("AT1\\AT4"));
            oSegment.set_DataElementValue(1,0,"COMMODITY 1");     //Lading Description
 
            //AT2 - BILL OF LADING LINE ITEM DETAIL
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("AT1\\AT2\\AT2"));
            oSegment.set_DataElementValue(1,0,"5");     //Lading Quantity
            oSegment.set_DataElementValue(2,0,"CTN");     //Packaging Form Code
            oSegment.set_DataElementValue(3,0,"N");     //Weight Qualifier
            oSegment.set_DataElementValue(4,0,"L");     //Weight Unit Code
            oSegment.set_DataElementValue(5,0,"210");     //Weight
            oSegment.set_DataElementValue(9,0,"999999-01");     //Commodity Code
 
            //MAN - MARKS AND NUMBERS
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("AT1\\AT2\\MAN"));
            oSegment.set_DataElementValue(1,0,"GM");     //Marks and Numbers Qualifier
            oSegment.set_DataElementValue(2,0,"00000858050113093100");     //Marks and Numbers
 
            //MAN - MARKS AND NUMBERS
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("AT1\\AT2\\MAN(2)"));
            oSegment.set_DataElementValue(1,0,"GM");     //Marks and Numbers Qualifier
            oSegment.set_DataElementValue(2,0,"00000858050113093101");     //Marks and Numbers
 
            //MAN - MARKS AND NUMBERS
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("AT1\\AT2\\MAN(3)"));
            oSegment.set_DataElementValue(1,0,"GM");     //Marks and Numbers Qualifier
            oSegment.set_DataElementValue(2,0,"00000858050113093102");     //Marks and Numbers
 
            //MAN - MARKS AND NUMBERS
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("AT1\\AT2\\MAN(4)"));
            oSegment.set_DataElementValue(1,0,"GM");     //Marks and Numbers Qualifier
            oSegment.set_DataElementValue(2,0,"00000858050113093103");     //Marks and Numbers
 
            //MAN - MARKS AND NUMBERS
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("AT1\\AT2\\MAN(5)"));
            oSegment.set_DataElementValue(1,0,"GM");     //Marks and Numbers Qualifier
            oSegment.set_DataElementValue(2,0,"00000858050113093104");     //Marks and Numbers
 
            //SPO - SHIPMENT PURCHASE ORDER DETAIL
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("AT1\\AT2\\SPO"));
            oSegment.set_DataElementValue(1,0,"PO123567");     //Purchase Order Number
            oSegment.set_DataElementValue(2,0,"RF1144");     //Reference Identification
            oSegment.set_DataElementValue(3,0,"CP");     //Unit or Basis for Measurement Code
            oSegment.set_DataElementValue(4,0,"12");     //Quantity
 
            //SPO - SHIPMENT PURCHASE ORDER DETAIL
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("AT1\\AT2\\SPO(2)"));
            oSegment.set_DataElementValue(1,0,"PO456789");     //Purchase Order Number
            oSegment.set_DataElementValue(2,0,"RF1144");     //Reference Identification
            oSegment.set_DataElementValue(3,0,"CP");     //Unit or Basis for Measurement Code
            oSegment.set_DataElementValue(4,0,"15");     //Quantity
 
            //TRAILING SEGMENTS ARE AUTOMATICALLY CREATED 

            //DISPLAY EDI STRING
            MessageBox.Show(oEdiDoc.GetEdiString(),"EDI File");

            //SAVE THE EDI DOCUMENT OBJECT INTO AN EDI FILE.
            oEdiDoc.Save(sPath + sEdiFile);

            MessageBox.Show(sPath + sEdiFile, "EDI File saved");
 
            //DESTROYS OBJECTS
            oSegment.Dispose();
            oTransactionset.Dispose();
            oGroup.Dispose();
            oInterchange.Dispose();
            oSchema.Dispose();
            oSchemas.Dispose();
            oEdiDoc.Dispose();

        }
    

    Click here to download a trial version of the Framework EDI