How do I copy a file using BizTalk Server?

I’m using BizTalk to transfer a file from one place to another. How can I make sure the filename stays the same at the destination?


Peter, an online friend of mine whose company specialises in cruises is doing some integration work using Microsoft BizTalk 2006 R2. One of the tasks he needs to accomplish is to move a file from one location to another. By default, when you set up a send port using BizTalk, the destination file name is set to %MessageID%.xml. which means the filename ends up being a GUID with a .xml extension. Peter wanted the name of the file to be preserved when writing to the destination folder.

It turns out that BizTalk has a number of different macros that can be used for constructing a destination filename. The send handler substitutes the macro for an actual value when writing out the file. Here are the macros I’ve managed to come up with:

%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
%datetime%
UTC date time in format YYYY-MM-DDThhmmss
%datetime.tz%
Local date time + time zone from GMT in format YYYY-MM-DDThhmmssTZD,
%time%
UTC time in format hhmmss
%time.tz%
Local time + time zone from GMT in format hhmmssTZD
%SourceFileName%
Name of the file as stored in the message context by the receive handler

Now, just a couple of things to keep in mind. %SourceFileName% doesn’t require an extension as this is carried with the filename. Also, keep in mind that if you’re picking up the same filename you could run into clashes in the destination folder. The other macros pretty much guarantee a unique filename, but %SourceFileName% doesn’t. If you keep BizTalk’s default settings for the send port, the message will get suspended as BizTalk will be unable to write the file into the folder. You can however specify that you want to file to be overwritten with the new version.

Hope this helps

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.