X12Reader error in InterchangeHeader


1 comment

  • Avatar
    Don Zoeggerle


    You can access the interchange control number like this:

    1. When using ReadToEnd() - this would have read ALL the data in the file so potentially multiple interchange control numbers. You need to tell which interchange control number exactly, that's why CurrentInterchangeHeader is NULL because there is no current:

    using (var ediReader = new X12Reader(ediStream, TemplateFactory.TrialTemplateFactory))
    x12Items = ediReader.ReadToEnd().ToList();

    var firstIcn = ediItems.OfType<ISA>().First().InterchangeControlNumber_13;
    Console.WriteLine("ICN:{0}", firstIcn );

    2. When using Read(), you can use the CurrentInterchangeHeader because it's still iterating through the items:

    using (var ediReader = new X12Reader(ediStream, LoadFactory))
    var icn = ediReader.CurrentInterchangeHeader.InterchangeControlNumber_13;
    Console.WriteLine("ICN:{0}", icn);
    Comment actions Permalink

Please sign in to leave a comment.