Biztalk 2004 provides a variety of built in macros for dynamically naming files.  A full list of macros can be found in the help guide or here. 

Recently, I have been looking at SourceFileName.  I have posted a sample in the past that covers how to name output files inside your Orchestration using the %SourceFileName% macro.  In that sample, I completely override the File.ReceivedFileName property with a new value.  The File.ReceivedFileName property is the data source for the %SourceFileName% macro.

What if I wanted to append or prepend data to the original file name?  When using the File Receive Adapter, the File.ReceivedFileName property looks like this: “c:\somepath\FileName.xml”. 

If you prepend or appended text to this, you will get “PrePend_c:\somepath\FileName.xml” or “c:\somepath\FileName.xml_Append”. 

When the %SourceFileName% macro runs, it looks for the last “\” and truncates the beginning part of the filename.  So, in the Prepend case, the prepended text is completely lost.

How can I prepend or append text to the filename?  Easy, just use a simple static helper class to prep the filename.  The method to prepend text would look like this:

public static string PrePendText(string sReceivedFileName, string sPreppendText)


 int nLastIndex = sReceivedFileName.LastIndexOf(@”\”);

 return sPreppendText + sReceivedFileName.Substring(nLastIndex+1);


I have put together a sample with three methods; one to prepend text, one to append text, and one to append text and change the file extension. 

Download: Prepend and Append Text to Filename Sample

Setup is easy.  Just deploy the Orchestration and do not forget to GAC the Helper class.