Validating EDI Files I

Index

    Validating EDI Files I

    Validating EDI files is extremely simple. Just set a few properties and you’re ready to go.

    Example

    // Create an instance of the EDIValidator object
    EDIValidator validator = new EDIValidator();

    validator.AutoDetectDelimiters = true;

    // Set the type of EDI file that you are about the validate
    validator.EDIFileType = FileType.X12;

    // Set the source of EDI data, whether you are validating from an in-memory string or a file
    validator.EDISource = EDISource.File; // Or EDISource.DataString

    // Set the EDI rules file.  The entire EDI Rules can also be passed in using the ‘EDIRuleFileData’ property
    validator.EDIRulesFile = “C:\\EDIFile.Rules“;

    // Set the EDI file to validate
    validator.EDIFile = “C:\\EDIFile.txt“;

    // Validate
    validator.Validate();

    // Check if the EDI file passed
    if (validator.Passed)
    {
       Console.WriteLine(“Passed”);

       //Get the EDI file just parsed
       EDILightWeightDocument file = validator.EDILightWeightDocument;
    }
    else
    {
       // Display all errors

    foreach (EDIError error in ediValidator.Errors)
       {
          Console.WriteLine(error.LineNumber.ToString() + ” ” + error.Loop + ” ” + error.Segment + ” ” + error.Message.ToString());
       }

    }

    If you just want to validate the EDI file and not load it just set the LoadValidatedData property to false. In this case EDILightWeightDocument will be null after validation.

    Prior to RDPCrystal EDI Library 4.0 a ValidationException could have been thrown if an unexpected exception occurred. Currently if an unexpected error occurs an Error object is created and returned in the Errors collection. In this case an EDIValidationMessage type of UnexpectedError or MalformedEDIFile is returned in the Error object. An exception will be thrown if the file to validate is not found or the rules file to use is not found.

    Segment must also appear in the same order as they are mentioned in the implementation guide.

    in EDI Validator
    Did this article answer your question?