BizTalk 2004 Trick: Macros for Constructing Filenames in Files Send Handler

Updateupdated 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.

13 Comments

  • are user defined macros allowed? I was trying to use %src_filename% (from 2002 documentation) but it is not defined for 2004.

  • don't think so Mike...

  • What if I want to keep the same name of a file. For example, if the file on the recieve port is foo.xml I want the send port to send the file as foo.xml. Can this be done?

  • You want to use %SourceFileName% - it's case sensitive.

  • I fear that some messages will get overwritten using the plain datetime mask. I hope the UTC one will suffice!

  • Attention:



    works: C:\Test\%SourceFileName%.xml

    won't work: C:\Test\Test_%SourceFileName%.xml



    under BTS 2004

  • Sorry, I tried on and found out that the file-adapter for non-XML files doesn's recognize the %SourceFileName% property! Does anyone know about this issue?

  • As a re on Martin Kirsch's:

    works: C:\Test\%SourceFileName%.xml

    won't work: C:\Test\Test_%SourceFileName%.xml



    Strange because:

    C:\BT2004demo\%datetime%_%messageid%.xml

    works just fine here.

  • There is no property called "SourceFileName".

    I checked with all possible combinations.



    It didnot work



    venkat.

  • There is no property called "SourceFileName".

    I checked with all possible combinations.



    It didnot work



    venkat.

  • It appears that the %SourceFileName% property is not recognized in non-XML files. Does ANYBODY have any clue on how to access the source file name in an orchestration for non-XML files?



    Thanks

    C

  • Hi,
    I am trying to use "Application Report for file %SourceFileName%" for SMTP adapter. %SourceFileName%" works for file adapters but not for smtp adapter. I tried using TempFile name = System.Convert.ToString(FILE.ReceiveFilename); and then pass it to EmailMessage = "The file name "+ TempFile + "was sucessfully processed.";
    I get an error Error 12 illegal use of identifier 'FILE.ReceivedFileName' in an expression. Any sugesstion is much appreciated.
    Many thanks
    Dragonheart

  • I am using %MessageID% macro but I want my file name should be 555F3418-D99E-4E51-800A-6E89CFD8B1D7.xml instead of {555F3418-D99E-4E51-800A-6E89CFD8B1D7}.xml how can i do this

Comments have been disabled for this content.