private void btnGenerate_Click(object sender, System.EventArgs e)
        {
            ediDocument oEdiDoc = null;
            ediSchema oSchema = null;
            ediSchemas oSchemas = null;
            ediInterchange oInterchange = null;
            ediTransactionSet oTransactionset = null;
            ediDataSegment oSegment = null;

            string sPath = AppDomain.CurrentDomain.BaseDirectory;
            string sSefFile = "DESADV_D96A.EVAL0.SEF";
            string sEdiFile = "desadv_output.edi";
 
            //CREATES OEDIDOC OBJECT
            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);
 
            //LOADS THE SEF FILE
            ediSchema.Set(ref oSchema, (ediSchema) oEdiDoc.LoadSchema(sPath + sSefFile, 0));
 
            //SET TERMINATORS
            oEdiDoc.SegmentTerminator = "'";
            oEdiDoc.ElementTerminator = "+";
            oEdiDoc.CompositeTerminator = ":";
            oEdiDoc.ReleaseIndicator = "?";
 
            //CREATES THE UNB SEGMENT
            ediInterchange.Set(ref oInterchange, (ediInterchange) oEdiDoc.CreateInterchange("UN","D96A"));
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oInterchange.GetDataSegmentHeader());
            oSegment.set_DataElementValue(1,1, "UNOA");     //Syntax identifier
            oSegment.set_DataElementValue(1,2, "2");     //Syntax version number
            oSegment.set_DataElementValue(2,1, "00009501L");     //Interchange sender identification
            oSegment.set_DataElementValue(2,2, "ZZZ");     //Partner identification code qualifier
            oSegment.set_DataElementValue(3,1, "CUSMOD");     //Recipient identification
            oSegment.set_DataElementValue(3,2, "ZZZ");     //Partner identification code qualifier
            oSegment.set_DataElementValue(4,1, "040910");     //Date
            oSegment.set_DataElementValue(4,2, "1914");     //Time
            oSegment.set_DataElementValue(5,0,"IRN000601");     //Interchange control reference
 
            //CREATES THE UNH SEGMENT
            ediTransactionSet.Set(ref oTransactionset, (ediTransactionSet) oInterchange.CreateTransactionSet("DESADV"));
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.GetDataSegmentHeader());
            oSegment.set_DataElementValue(1,0,"1");     //Message reference number
            oSegment.set_DataElementValue(2,1,"DESADV");     //Message type identifier
            oSegment.set_DataElementValue(2,2,"D");     //Message version number
            oSegment.set_DataElementValue(2,3,"96A");     //Message release number
            oSegment.set_DataElementValue(2,4,"UN");     //Controlling agency
 
            //BGM - BEGINNING OF MESSAGE
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("BGM"));
            oSegment.set_DataElementValue(1,1,"351");     //Document/message name, coded
            oSegment.set_DataElementValue(2,0,"00245828");     //Document/message number
 
            //DTM - DATE/TIME/PERIOD
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("DTM"));
            oSegment.set_DataElementValue(1,1,"137");     //Date/time/period qualifier
            oSegment.set_DataElementValue(1,2,"200404201000");     //Date/time/period
            oSegment.set_DataElementValue(1,3,"203");     //Date/time/period format qualifier
 
            //MEA - MEASUREMENTS
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("MEA"));
            oSegment.set_DataElementValue(1,0,"AAX");     //Measurement purpose qualifier
            oSegment.set_DataElementValue(2,1,"AAD");     //Property measured, coded
            oSegment.set_DataElementValue(3,1,"KGM");     //Measure unit qualifier
            oSegment.set_DataElementValue(3,2,"456424");     //Measurement value
 
            //NAD - NAME AND ADDRESS
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("NAD\\NAD"));
            oSegment.set_DataElementValue(1,0,"CZ");     //Party qualifier
            oSegment.set_DataElementValue(2,1,"0931353513609");     //Party identification
            oSegment.set_DataElementValue(2,3,"10");     //Code list responsible agency, coded
            oSegment.set_DataElementValue(4,1,"MORA AZERGUES");     //Party name
 
            //NAD - NAME AND ADDRESS
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("NAD(2)\\NAD"));
            oSegment.set_DataElementValue(1,0,"SE");     //Party qualifier
            oSegment.set_DataElementValue(2,1,"0931353513609");     //Party identification
            oSegment.set_DataElementValue(2,3,"10");     //Code list responsible agency, coded
            oSegment.set_DataElementValue(4,1,"MORA AZERGUES");     //Party name
 
            //RFF - REFERENCE
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("NAD(2)\\RFF\\RFF"));
            oSegment.set_DataElementValue(1,1,"ADE");     //Reference qualifier
            oSegment.set_DataElementValue(1,2,"58292");     //Reference number
 
            //NAD - NAME AND ADDRESS
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("NAD(3)\\NAD"));
            oSegment.set_DataElementValue(1,0,"CA");     //Party qualifier
            oSegment.set_DataElementValue(2,1,"0931353514115");     //Party identification
            oSegment.set_DataElementValue(2,3,"10");     //Code list responsible agency, coded
            oSegment.set_DataElementValue(4,1,"AB TRANSPORTEUR");     //Party name
 
            //RFF - REFERENCE
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("NAD(3)\\RFF\\RFF"));
            oSegment.set_DataElementValue(1,1,"ADE");     //Reference qualifier
            oSegment.set_DataElementValue(1,2,"10115");     //Reference number
 
            //NAD - NAME AND ADDRESS
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("NAD(4)\\NAD"));
            oSegment.set_DataElementValue(1,0,"CN");     //Party qualifier
            oSegment.set_DataElementValue(2,1,"ETAPLES");     //Party identification
 
            //LOC - PLACE/LOCATION IDENTIFICATION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("NAD(4)\\LOC"));
            oSegment.set_DataElementValue(1,0,"11");     //Place/location qualifier
            oSegment.set_DataElementValue(2,1,"ETAPLES");     //Place/location identification
 
            //RFF - REFERENCE
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("NAD(4)\\RFF\\RFF"));
            oSegment.set_DataElementValue(1,1,"ADE");     //Reference qualifier
            oSegment.set_DataElementValue(1,2,"61778");     //Reference number
 
            //TOD - TERMS OF DELIVERY OR TRANSPORT
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("TOD\\TOD"));
            oSegment.set_DataElementValue(1,0,"5");     //Terms of delivery or transport function, coded
            oSegment.set_DataElementValue(3,1,"EXW");     //Terms of delivery or transport, coded
 
            //TDT - TRANSPORT INFORMATION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("TDT\\TDT"));
            oSegment.set_DataElementValue(1,0,"12");     //Transport stage qualifier
            oSegment.set_DataElementValue(3,1,"ROU");     //Mode of transport, coded
            oSegment.set_DataElementValue(8,5,"FR");     //Nationality of means of transport, coded
 
            //EQD - EQUIPMENT DETAILS
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("EQD\\EQD"));
            oSegment.set_DataElementValue(1,0,"TE");     //Equipment qualifier
            oSegment.set_DataElementValue(2,1,"9999 TR 99");     //Equipment identification number
 
            //CPS - CONSIGNMENT PACKING SEQUENCE
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CPS\\CPS"));
            oSegment.set_DataElementValue(1,0,"1");     //Hierarchical id. number
            oSegment.set_DataElementValue(3,0,"1");     //Packaging level, coded
 
            //PAC - PACKAGE
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CPS\\PAC\\PAC"));
            oSegment.set_DataElementValue(1,0,"4");     //Number of packages
            oSegment.set_DataElementValue(3,1,"CARTON BLEU");     //Type of packages identification
            oSegment.set_DataElementValue(3,3,"92");     //Code list responsible agency, coded
 
            //QTY - QUANTITY
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CPS\\PAC\\QTY"));
            oSegment.set_DataElementValue(1,1,"52");     //Quantity qualifier
            oSegment.set_DataElementValue(1,2,"1020");     //Quantity
            oSegment.set_DataElementValue(1,3,"PCE");     //Measure unit qualifier
 
            //PCI - PACKAGE IDENTIFICATION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CPS\\PAC\\PCI\\PCI"));
            oSegment.set_DataElementValue(1,0,"17");     //Marking instructions, coded
 
            //RFF - REFERENCE
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CPS\\PAC\\PCI\\RFF"));
            oSegment.set_DataElementValue(1,1,"AAT");     //Reference qualifier
            oSegment.set_DataElementValue(1,2,"000013943");     //Reference number
 
            //GIR - RELATED IDENTIFICATION NUMBERS
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CPS\\PAC\\PCI\\GIR"));
            oSegment.set_DataElementValue(1,0,"3");     //Set identification qualifier
            oSegment.set_DataElementValue(2,1,"490345661");     //Identity number
            oSegment.set_DataElementValue(2,2,"ML");     //Identity number qualifier
 
            //GIR - RELATED IDENTIFICATION NUMBERS
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CPS\\PAC\\PCI\\GIR(2)"));
            oSegment.set_DataElementValue(1,0,"3");     //Set identification qualifier
            oSegment.set_DataElementValue(2,1,"490345664");     //Identity number
            oSegment.set_DataElementValue(2,2,"ML");     //Identity number qualifier
 
            //PCI - PACKAGE IDENTIFICATION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CPS\\PAC\\PCI(2)\\PCI"));
            oSegment.set_DataElementValue(1,0,"17");     //Marking instructions, coded
 
            //RFF - REFERENCE
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CPS\\PAC\\PCI(2)\\RFF"));
            oSegment.set_DataElementValue(1,1,"AAT");     //Reference qualifier
            oSegment.set_DataElementValue(1,2,"000013944");     //Reference number
 
            //GIR - RELATED IDENTIFICATION NUMBERS
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CPS\\PAC\\PCI(2)\\GIR"));
            oSegment.set_DataElementValue(1,0,"3");     //Set identification qualifier
            oSegment.set_DataElementValue(2,1,"490345665");     //Identity number
            oSegment.set_DataElementValue(2,2,"ML");     //Identity number qualifier
  
            //LIN - LINE ITEM
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CPS\\LIN\\LIN"));
            oSegment.set_DataElementValue(1,0,"1");     //Line item number
            oSegment.set_DataElementValue(3,1,"2547879");     //Item number
            oSegment.set_DataElementValue(3,2,"IN");     //Item number type, coded
 
            //PIA - ADDITIONAL PRODUCT ID
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CPS\\LIN\\PIA"));
            oSegment.set_DataElementValue(1,0,"1");     //Product id. function qualifier
            oSegment.set_DataElementValue(2,1,"11164901");     //Item number
            oSegment.set_DataElementValue(2,2,"SA");     //Item number type, coded
 
            //IMD - ITEM DESCRIPTION
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CPS\\LIN\\IMD"));
            oSegment.set_DataElementValue(3,4,"CAPSULE DE ROULEMENT");     //Item description
 
            //QTY - QUANTITY
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CPS\\LIN\\QTY"));
            oSegment.set_DataElementValue(1,1,"12");     //Quantity qualifier
            oSegment.set_DataElementValue(1,2,"4080");     //Quantity
            oSegment.set_DataElementValue(1,3,"PCE");     //Measure unit qualifier
 
            //RFF - REFERENCE
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CPS\\LIN\\RFF\\RFF"));
            oSegment.set_DataElementValue(1,1,"ON");     //Reference qualifier
            oSegment.set_DataElementValue(1,2,"0000009301");     //Reference number
 
            //DTM - DATE/TIME/PERIOD
            ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("CPS\\LIN\\RFF\\DTM"));
            oSegment.set_DataElementValue(1,1,"4");     //Date/time/period qualifier
            oSegment.set_DataElementValue(1,2,"20040420");     //Date/time/period
            oSegment.set_DataElementValue(1,3,"102");     //Date/time/period format qualifier
 
            MessageBox.Show(oEdiDoc.GetEdiString(), "DESADV D96A EDI string");

            //TRAILING SEGMENTS ARE AUTOMATICALLY CREATED WHEN FREDI COMMITS (SAVES) THE EDIDOC OBJECT INTO A FILE.
            oEdiDoc.Save(sPath + sEdiFile);

            MessageBox.Show("Done");

        }
    

    Click here to download a trial version of the Framework EDI