Validating EDI Files I


    Validating EDI Files I

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


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

    // 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

    // Check if the EDI file passed
    if (validator.Passed)

       //Get the EDI file just parsed
       EDILightWeightDocument file = validator.EDILightWeightDocument;
       // 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?