private void btnGenerate_Click(object sender, EventArgs e) { ediDocument oEdiDoc; ediSchema oSchema; ediSchemas oSchemas; ediInterchange oInterchange; ediGroup oGroup; ediTransactionSet oTransactionSet; ediDataSegment oSegment; string sEdiFileName = ""; string sSefFileName = ""; string sBinFilename = "edidev_logo.jpg"; string sPath = AppDomain.CurrentDomain.BaseDirectory; // Create the top-level application object "ediDocument". oEdiDoc = new ediDocument(); // This makes certain that Framework EDI only uses the SEF file provided, // and that it does not use its built-in Standard Reference table to generate // the EDI document oSchemas = (ediSchemas)oEdiDoc.GetSchemas(); oSchemas.EnableStandardReference = false; // The FORWARD-WRITE cursor increases the performance of processing the EDI // document (see Technical Note 3 below). oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardWrite; // Terminators have to be specified. oEdiDoc.SegmentTerminator = "~{13:10}"; oEdiDoc.ElementTerminator = "*"; oEdiDoc.CompositeTerminator = "!"; sEdiFileName = "841_004010.X12"; sSefFileName = "841_004010.EVAL0.SEF"; // Specify SEF file to load. oSchema = (ediSchema)oEdiDoc.LoadSchema(sPath + sSefFileName, SchemaTypeIDConstants.Schema_Standard_Exchange_Format); // Creates the Interchange Control Header segment (ISA). oInterchange = (ediInterchange)oEdiDoc.CreateInterchange("X", "004010"); oSegment = (ediDataSegment)oInterchange.GetDataSegmentHeader(); oSegment.set_DataElementValue(1, 0, "00"); // Authorization Information Qualifier (I01) oSegment.set_DataElementValue(2, 0, " "); // Authorization Information (I02) oSegment.set_DataElementValue(3, 0, "00"); // Security Information Qualifier (I03) oSegment.set_DataElementValue(4, 0, " "); // Security Information (I04) oSegment.set_DataElementValue(5, 0, "ZZ"); // Interchange ID Qualifier (I05) oSegment.set_DataElementValue(6, 0, "SENDER ID "); // Interchange Sender ID (I06) oSegment.set_DataElementValue(7, 0, "ZZ"); // Interchange ID Qualifier (I05) oSegment.set_DataElementValue(8, 0, "RECEIVER ID "); // Interchange Receiver ID (I07) oSegment.set_DataElementValue(9, 0, "010101"); // Interchange Date (I08) oSegment.set_DataElementValue(10, 0, "0101"); // Interchange Time (I09) oSegment.set_DataElementValue(11, 0, "U"); // Interchange Control Standards Identifier (I10) oSegment.set_DataElementValue(12, 0, "00401"); // Interchange Control Version Number (I11) oSegment.set_DataElementValue(13, 0, "000000001"); // Interchange Control Number (I12) oSegment.set_DataElementValue(14, 0, "0"); // Acknowledgment Requested (I13) oSegment.set_DataElementValue(15, 0, "T"); // Usage Indicator (I14) oSegment.set_DataElementValue(16, 0, "!"); // Component Element Separator (I15) // Creates the Functional Group Header segment (GS). oGroup = (ediGroup)oInterchange.CreateGroup("004010"); ediDataSegment.Set(ref oSegment, (ediDataSegment)oGroup.GetDataSegmentHeader()); oSegment.set_DataElementValue(1, 0, "SP"); // Functional Identifier Code (479) oSegment.set_DataElementValue(2, 0, "APP SENDER"); // Application Sender's Code (142) oSegment.set_DataElementValue(3, 0, "APP RECEIVER"); // Application Receiver's Code (124) oSegment.set_DataElementValue(4, 0, "01010101"); // Date (373) oSegment.set_DataElementValue(5, 0, "01010101"); // Time (337) oSegment.set_DataElementValue(6, 0, "1"); // Group Control Number (28) oSegment.set_DataElementValue(7, 0, "X"); // Responsible Agency Code (455) oSegment.set_DataElementValue(8, 0, "004010"); // Version / Release / Industry Identifier Code (480) // TRANSACTION SET ID 841 - Specifications/Technical Information // Creates the Transaction Set header segment (ST). oTransactionSet = (ediTransactionSet)oGroup.CreateTransactionSet("841"); ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionSet.GetDataSegmentHeader()); oSegment.set_DataElementValue(1, 0, "841"); // Transaction Set Identifier Code (143) oSegment.set_DataElementValue(2, 0, "0001"); // Transaction Set Control Number (329) // Specification Identifier (SPI) oSegment = oTransactionSet.CreateDataSegment(@"SPI\SPI"); oSegment.set_DataElementValue(1, 0, "06"); // Security Level Code (786) oSegment.set_DataElementValue(2, 0, "01"); // Reference Identification Qualifier (128) oSegment.set_DataElementValue(3, 0, "12345"); // Reference Identification (127) oSegment.set_DataElementValue(7, 0, "00"); // Transaction Set Purpose Code (353) oSegment.set_DataElementValue(8, 0, "AE"); // Report Type Code (755) oSegment.set_DataElementValue(9, 0, "11"); // Security Level Code (786) // Hierarchical Level (HL) oSegment = oTransactionSet.CreateDataSegment(@"HL\HL"); oSegment.set_DataElementValue(1, 0, "1"); // Hierarchical ID Number (628) oSegment.set_DataElementValue(2, 0, ""); // Hierarchical Parent ID Number (734) oSegment.set_DataElementValue(3, 0, "SD"); // Hierarchical Level Code (735) oSegment.set_DataElementValue(4, 0, "0"); // Hierarchical Child Code (736) // Electronic Format Identification (EFI) oSegment = oTransactionSet.CreateDataSegment(@"HL\EFI\EFI"); oSegment.set_DataElementValue(1, 0, "06"); // Security Level Code (786) oSegment.set_DataElementValue(4, 0, ""); // Version Identifier (799) oSegment.set_DataElementValue(5, 0, ""); // Program Identifier (802) oSegment.set_DataElementValue(6, 0, ""); // Version Identifier (799) oSegment.set_DataElementValue(7, 0, ""); // Interchange Format (801) oSegment.set_DataElementValue(11, 0, sBinFilename); // File Name (803) // Binary Data (BIN) ediDataSegment.Set(ref oSegment, oTransactionSet.CreateDataSegment(@"HL\EFI\BIN")); oSegment.set_DataElementValue(1, 0, ""); // Length of Binary Data (784) oSegment.get_DataElement(2).ImportValue(sPath + sBinFilename); // Binary Data (785) // Trailing segments are automatically created when Framework EDI commits // (saves) the instance of "oEdiDoc" object into an EDI file. oEdiDoc.Save(sPath + sEdiFileName, 0); MessageBox.Show("Done. Use the eFileManager to open the EDI file located at " + sPath + sEdiFileName + @", and then view the binary file in segment HL\EFI\BIN" ); }