Stephen W. Thomas BizTalk Blog

100% Pure BizTalk
posts - 132, comments - 146, trackbacks - 438

My Links

News

Subscribe to my blog via:


Add to Google

Visit my website at:
www.BizTalkGurus.com

Archives

BizTalk 2004 Samples

BizTalk 2006 Samples

BizTalk Videos

BizTalk White Papers

BizTalkBlogs.com

Great BizTalk Blogs

Other Links

Biztalk 2004 Prepend to SourceFileName Macro Sample

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.

Print | posted on Monday, August 01, 2005 4:35 PM |

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 4 and 1 and type the answer here:

Powered by: