Click here to Skip to main content
13,296,377 members (52,720 online)
Click here to Skip to main content
Add your own
alternative version


21 bookmarked
Posted 16 Mar 2006

Using the %SourceFileName% Macro to Create a Custom Send File Name in BizTalk 2004

, 22 Mar 2006
Rate this:
Please Sign up or sign in to vote.
Using the send handler macro to create a custom send file name within BizTalk 2004


This article walks through the motions of creating a custom name using the %SourceFileName% macro for sending handlers within BizTalk 2004.


When working on a particular project, I had to adhere to a naming convention for one of our customers for one of the data files we were sending. The convention was:



The number part always needed to be 9 numbers and in sequence. So for ease, a database table is used to record each time a sequence number is created.

(The SQL scripts are available with the downloadable source code.)

C# Assembly

I then created a C# class which connects to the database to return the sequence number value.

(See downloadable source code).

I created three methods:

  1. GetSequenceNumber: This method (as the name suggests) uses the database methods to retrieve a new sequence number.
  2. PadSequenceNumber: This method returns the number of 0s to be placed in front of the sequence number returned from the database.
  3. GetFileName: This method is the one called in the BizTalk Orchestration to get the file name.
public static string GetFileName(string id) { 
string num = GetSequenceNumber(id); 
int i = num.Length; string name = PadSequenceNumber(i); 
string res = name + num; return res; 

BizTalk 2004 Project

For the purpose of this article, I have created a simple BizTalk project which takes an address from an XML file and outputs as an XML file.

Within this project, there is the address schema, the mapping between the schemas for the XML output and an orchestration for specifying the file name.


Sample screenshot - Click to enlarge image

The flow of the orchestration is as follows:

  1. A message is received from the specified receive location.
  2. It is then transformed using the Address map (Please note this is a dummy map which is not needed. In this example, I have tried to keep to the original project that I created).
  3. The receive file name is changed.
  4. The constructed message with new file name is sent to send location.

Within the Message Assignment shape (after the Transform Shape) is the code that sets the file name.

//get file name
filename = BizTalk.CustomOutputFile.CSharp.Filename.GetFileName("Address");

//sets the received file name to what is specified below
Address_Output(FILE.ReceivedFileName) = "VIS_HA_" + filename + ".xml";

Sample screenshot

As you can see, the message receive name is changed. This is done using the %SourceFileName% macro available for send handlers within BizTalk 2004.

See below for other macros available:

Macro name

Substitute value


Coordinated Universal Time (UTC) date time in the format YYYY-MM-DDThhmmss (for example, 1997-07-12T103508).


UTC date time in the format YYYYMMDDhhmmsss, where sss means seconds and milliseconds (for example, 199707121035234 means 1997/07/12, 10:35:23 and 400 milliseconds).

<p> </p>

Local date time plus time zone from GMT in the format YYYY-MM-DDThhmmssTZD, (for example, 1997-07-12T103508+800).


Name of the destination party. The value comes from message the context property BTS.DestinationParty.


Identifier of the destination party (GUID). The value comes from the message context property BTS.DestinationPartyID.


Qualifier of the destination party. The value comes from the message context property BTS.DestinationPartyQualifier.


Globally unique identifier (GUID) of the message in BizTalk Server. The value comes directly from the message context property BTS.MessageID.


Name of the file from where the File adapter reads the message. The file name includes extension and excludes the file path, for example, foo.xml. When substituting this property, the File adapter extracts the file name from the absolute file path stored in the FILE.ReceivedFileName context property. If the context property does not have a value, for example, if message was received on an adapter other than File adapter, then the macro will not be substituted and will remain in the file name as is (for example, C:\Drop\%SourceFileName%).


Name of the source party from which the File adapter received the message.


Identifier of the source party (GUID). The value comes from the message context property BTS.SourcePartyID.


Qualifier of the source party from which the File adapter received the message.


UTC time in the format hhmmss.

Local time plus time zone from GMT in the format hhmmssTZD (for example, 124525+530).

Port Configuration

I created a receive and sent port, specifying locations where I wanted the files to be dropped.

On the send port, I set the File name property to:


Sample screenshot


Once I had done this, I deployed the project. I started the orchestration and dropped a test file in the location and watch it create a file name using a sequence number.

End Note

  • This macro is case sensitive.
  • There is no need for the file extension on the end of this macro unlike other marcos.
  • Other send handler macros can be combined.

i.e. %MessageID%+ %time%.xml


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
United Kingdom United Kingdom
Currently a Microsoft Developer using an array of MS products ranging from BizTalk and Sharepoint to .NET 2.

You may also be interested in...


Comments and Discussions

QuestionTo get the name from the custom pipeline component in the send port Pin
sbanand20203-Jul-13 3:57
membersbanand20203-Jul-13 3:57 
QuestionHow to retain same file name for SOAP adapter. Pin
Dhiraj Bhavsar30-Oct-12 4:00
memberDhiraj Bhavsar30-Oct-12 4:00 
GeneralThanks Pin
Akshay Shaha7-Aug-12 2:02
memberAkshay Shaha7-Aug-12 2:02 
GeneralThanks! Pin
graulstone28-Sep-06 21:50
membergraulstone28-Sep-06 21:50 
GeneralTODO Pin
Naveen Karamchetti22-Mar-06 4:11
memberNaveen Karamchetti22-Mar-06 4:11 
NewsRe: TODO Pin
vish197922-Mar-06 5:54
membervish197922-Mar-06 5:54 
GeneralTODO Pin
Naveen Karamchetti22-Mar-06 4:10
memberNaveen Karamchetti22-Mar-06 4:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 22 Mar 2006
Article Copyright 2006 by vish1979
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid