Splitting Files

Index

    Splitting Files

    EDIFileSplitter is capable of splitting an X12 EDI files into many smaller files. The splitting operation is asynchronous by nature allowing program flow to continue. The resulting files will be placed in the directory specified.

    Developers can split file at the envelope level (ISA), the functional group level (GS) , or the header level (ST) by setting the FileSplitLevel property of EDIFileSplitter. After splitting the file the OnFileOperationCompletedEvent will be fired. Note that the event will be fired from a different thread.

    Example

    EDIFileSplitter ediFileSplitter = new EDIFileSplitter();
     
    // Split the file at the header level (ST segment)
    ediFileSplitter.FileSplitLevel = FileSplitLevel.HEADER;
     
    // Place 2 ST headers per file
    ediFileSplitter.NumberOfItemsPerFile = 2;
    ediFileSplitter.OnFileOperationCompleted += new EventHandler(splitter_OnFileOperationCompleted);

    try
    {
       string currentDirectory = Directory.GetCurrentDirectory();
       ediFileSplitter.Split(“837P_2ST_SE_Loops.txt”, currentDirectory);
    }
    catch (Exception ex)
    {
       MessageBox.Show(ex.Message);
    }

    private void splitter_OnFileOperationCompleted(object sender, FileOperationCompletedEventArgs e)
    {
        if (e.Status != FileOperationStatus.Success)
        {
           MessageBox.Show(“Error splitting file”, “Error”);
        }
        else if (e.Status == FileOperationStatus.Success)
        {
           MessageBox.Show(“File Split Success”, “Success”);
        }
        //e.SplitFiles will contain the names of the newly created split files
    }

    EDIFileSplitter will add the correct number of items in element 1 of the SE, GE, and IEA segments.

    in EDI File Splitter
    Did this article answer your question?