This question and response came up on a forum. I've never seen this referenced before so I thought it was worth blogging.
Problem:
BizTalk is receiving a flat file (can contain up to a million records) and doing a disassemble in a pipeline using a flat file schema. The individual messages are processed by a sequential convoy (Singleton) based on a correlation. The orchestration receives the message in a loop that follows the correlation set from the receive port where receive location split the flat file into smaller messages.
To specify a proper exit criteria to exit the loop and stop the convoy I need to know the number of messages in the flat file. But since I am using the default flat file disassembler, I have no clue how many messages are in the file.
Solution:
There’s a property promoted in the last of the disassembled messages in an interchange: BTS.LastInterchangeMessage = true. This tells you the last message in the interchange and in conjunction with BTS.InterchangeSequenceNumber you can tell the total number of messages in the interchange (in case you get them out of order).