Friday, February 20, 2004 6:37 PM Jan Tielens

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.

Filed under:

Comments

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

Wednesday, March 10, 2004 3:08 PM by Mike

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

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

Thursday, March 11, 2004 12:49 AM by Jan

don't think so Mike...

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

Friday, March 12, 2004 11:46 AM by Jim Martin

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?

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

Tuesday, March 16, 2004 10:06 AM by Mike

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

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

Thursday, March 18, 2004 11:09 AM by Jim Martin

Thank you so much! Now why didn't they put that in the documentation???

# File Send Handler Macros

Friday, March 19, 2004 4:37 AM by TrackBack

# BizTalk 2004 File Send Handler Macros

Friday, March 19, 2004 5:33 AM by TrackBack

# BizTalk 2004 File Send Handler Macros Bis

Friday, March 19, 2004 5:34 AM by TrackBack

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

Monday, April 12, 2004 5:22 PM by Rich Morrison

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

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

Tuesday, June 15, 2004 10:50 AM by Martin Kirsch

Attention:

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

under BTS 2004

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

Friday, June 18, 2004 4:16 AM by Martin Kirsch

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?

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

Monday, June 21, 2004 10:53 AM by Joris Arts

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.

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

Friday, July 09, 2004 2:26 AM by venkat

There is no property called "SourceFileName".
I checked with all possible combinations.

It didnot work

venkat.

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

Friday, July 09, 2004 2:26 AM by venkat

There is no property called "SourceFileName".
I checked with all possible combinations.

It didnot work

venkat.

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

Sunday, July 25, 2004 9:59 AM by cjvandyk

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

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

Tuesday, July 25, 2006 6:48 PM by Adam

To access the file name of Non XML Files in Biztalk orchestration see the following link.

http://www.developer.com/net/net/article.php/11087_3482346_2

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

Tuesday, July 25, 2006 6:54 PM by Adam

To Access the file name of messages in BizTalk Orchestration, also try this link.

http://www.topxml.com/Biztalk-Adapters/re-2694_Naming-Output-Files-in-an-Orchestration-in-BizTalk-2004.aspx

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

Monday, October 02, 2006 9:18 AM by Psss %SourceFileName% to SMTP adaptor in BizTalk 2006

Hi,

I am trying to use <b>"Application Report for file %SourceFileName%"</b> 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

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

Tuesday, January 16, 2007 6:08 PM by Sovana Shrestha

Hi,

I need to send a file with todays date. I used  %date%_%SourceFileName% but didnot work.

Any suggessation?

Regards

Sovana

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

Friday, September 28, 2007 1:57 AM by Arun

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