BizTalk 2004 Trick: Macros for Constructing Filenames in Files Send Handler
Update: updated list here.
Probably this trick is known already by most of the BizTalk users, but I had to search some time to figure it out (blush). Probably every demo of BizTalk 2004 you'll see uses a Send File Port that sends messages to a directory and most of the time these files will have a GUID as a filename, so each message sent will have a different name. No big deal you'd think, but I was actually looking for how to give these files such a name! The solution is to use “macros” in the URI property of the Sender Port, kinda strange name I think but it works. :-) So the URI property could look like “c:\temp\out\%MessageID%.xml“. Everything between the percentage signs (including themselves) will be replaced by the GUID which is of course unique.
From the docs: The files in which the files send handler writes messages can be created dynamically using a predefined set of macros. Before creating a file on file system, the files send handler substitutes all the macros in file name with their individual values. Several different macros can be used in one file name. The file name macros can be used while configuring the file send handler in BizTalk Explorer, or using the Explorer object model.
- %MessageID%
Unique identifier of the message in BizTalk Server (GUID). The value is taken directly from message context property BTS.MessageID - %datetime_bts2000%
UTC date time in format YYYYMMDDhhmmsss, where sss means seconds and milliseconds (e.g. 199707121035234 means 1997/07/12, 10:35:23 and 400 milliseconds) - %datetime%
UTC date time in format YYYY-MM-DDThhmmss (e.g. 1997-07-12T103508) - %datetime.tz%
Local date time + time zone from GMT in format YYYY-MM-DDThhmmssTZD, (e.g. 1997-07-12T103508+800) - %time%
UTC time in format hhmmss - %time.tz%
Local time + time zone from GMT in format hhmmssTZD (e.g. 124525+530)
Update (thanks to Mike's comments): %SourceFileName% (it's case sensitive): name of the file that was received by the receive port.