Stephen W. Thomas BizTalk Blog

100% Pure BizTalk
posts - 133, comments - 192, trackbacks - 427

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

Naming Output Files in an Orchestration in BizTalk 2004

In many cases it can be useful to know the exact name of your output file that will be sent from your Orchestration using the File Adapter.  This can be difficult if you are using the %MessageId%.xml macro to write the file since this it set after the message is sent from the Orchestration. 

 

Delivery Notification can help you determine if your message was sent successfully but it can not give you the file name.

 

BizTalk 2004 has two ways to dynamically name your files from inside the Orchestration.  The two ways to accomplish this are either to use a Dynamic Send Port or to use the %SourceFileName% macro on the Send Port.

 

Dynamic Send Port

Dynamitic Send Ports are powerful and useful if you need to send your files to many different locations on the file system like sometime to C:\data\ and other times c:\root\.  The downside is you need to have all this information inside your message or hard code it in the Orchestration.  So, it can be difficult to change.

 

Source File Name Macro

This is my preferred approach to Output File Naming.  This does not require your data or the Orchestration to have any idea as to the directory you want to write your file to.  This requires using the %SourceFileName% macro to set the output file name inside the Send Port. 

 

Don’t want the same name as your input file you say?  Now, here is the trick.  Just change the File.ReceivedFileName property inside the Orchestration to be anything you want!  This can be done by creating a new message and changing the context property.  The code inside a Message Assignment shape would look like this:

 

// Create a new message

OutMessage = InMessage;

 

// Set the ReceivedFileName context property

OutMessage(FILE.ReceivedFileName) = "SetInOrch.xml";

 

It is not required to demote this value into your message.  So, this method works with the Pass Through Send Pipeline because this context value is used by the File Adapter and not the pipeline.

 

CRITICAL: The %SourceFileName% macro does not need an additional extension (like .xml or .txt) after it like the %MessageId% macro.

 

I have put together a simple sample showing both of these types of file naming.  For information on how to run the samples, please see the Read Me file.

 

DOWLOAD: Sample Naming Output Files

 

Print | posted on Saturday, November 13, 2004 6:40 PM |

Feedback

Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

Stephen,
I have tried this, but I can't get it to work for me. I copied your solution almost verbatim, substituting my own directory and file names. The only real difference is that I am using a custom flat file pipeline and you are using xml. I need to have the output file named the same as the input file, but my output filename is simply C:\customer\OUT\%SourceFileName%.
4/21/2005 2:26 PM | Nathan
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

Well, now it appears to be working. It started working after a stop/restart of the Biztalk Service. I don't understand why I should have to stop and start the service over a map change or an orchestration change. I had to start and stop once to get a change of a record delimiter in a schema to take effect.
4/21/2005 5:12 PM | Nathan
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

Yep, the first rule when developing with BizTalk Server 2004: Always stop and start the host when making changes.

Stephen W. Thomas
4/25/2005 3:09 PM | Stephen W. Thomas
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

Hi
I am trying to use the above said method for changing the file, basically I need to append TimeStamp with the existing File name. And I am using Expression editor to do change the file name.

MyOutMessage(FILE.ReceivedFileName)= %SourceFileName% + %time%;

But getting an error saying illegal character at "%"

Please help me in this regard...
8/1/2005 9:36 AM | Sunil
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

You can only use the %SourceFileName% + %time% macros on the Send port themselves. Not inside an Expression shape. Inside an expression shape you would need to use something like System.Date.Now.ToString().

Move these to your Send Port and it should work for you.

I’m posting another sample working with SourceFileName later today.

Stephen W. Thomas
8/1/2005 9:41 AM | Stephen W. Thomas
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

basically I need to copy these files into multiple location so I am using Dynamic Port

Would you please give me an example for
how to use System.Date.Now.ToString() to append to the existing File name in Expression editor.
8/1/2005 10:16 AM | Sunil
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

Thank You very much, Now I am able to do it.
8/1/2005 11:35 AM | Sunil
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004



I am not using any orchestrations for the flow but I need to rename the file based on a dynamic value. How do I get the value to my port. This value is a field in the file

How do I the same?
10/25/2005 3:59 AM | Bhaskar K B
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

Hi

I need to increase the outputfile number for each file. i.e Files 01

Your help is much appreciated.

Kay
11/1/2005 8:47 AM | Kay
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

I have tried using the %SourceFileName% in the SendPort within the BizTalk explorer. Does not help. I am getting file in the out folder with the name %SourceFileName% What could be wrong?
12/21/2005 2:24 PM | Nitin
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

Hi,
How could i do the same in a pipeline helper class?
Regards,
AP
6/2/2006 4:31 AM | AP
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

Hi, I have the same problem as Mr Black. My input message is taken from MQSeries. I found an article in this Blog "http://weblogs.asp.net/jan/archive/2004/03/19/92701.aspx". He explain that "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%).
".Consequently I try to use dynamic port . My requirement is to write message in file copy mode=append because I must to maintain the ordering.

I try to set:
OutXml(FILE.CopyMode) = 0, (for append file sends)
but I found message routing failure. This is a specified message :"The FILE send adapter cannot open file for writing. Details The file exists."

Do you know if I can set these for Dynamic Ports ? It support that ? How can I solve ?

Excuse me for bad english.
Thanks in advance

Silvia

6/18/2006 11:02 PM | silvia
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

Hi,
for all people that have this problem
Dynamic port support Append files sends, the important is set MsgOutput(FILE.CopyMode)= 0 before the line where set the address.

So it work correctly.

Thank's
Silvia

6/20/2006 5:04 AM | silvia
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

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
10/2/2006 4:51 AM | Dragonheart
Gravatar

# USING SOURCEFILE names in SMTP adapter in BizTalk 2004

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
10/2/2006 6:45 AM | Dragonheart
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

You should be able to access inside an Expression shape but I think your code it wrong. It should be something like: TempFileName = Message(File.ReceivedFileName) with Message being your input message.

Hope this helps.

Stephen W. Thomas
10/10/2006 8:09 PM | Stephen W. Thomas
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

Hi,

When i write
Test10SendMsgInc = Test10RecMsgInc;
in the expression editor of the MessageAssignment i get an error: "cannot implicitly convert type 'message XMLInputFile1' to 'message FlatFileSchema1' "
where Test10SendMsgInc and the Test10RecMsgInc are the messages. I have set the MessageType of Test10SendMsgInc message as Test10Project.FlatFileSchema1
and MessageType of Test10RecMsgInc as Test10Project.XMLInputFile1.

FlatFileSchema1 and XMLInputFile1 are my output and input schemas respectively

I have used custom Receive pipeline with XML Disassembler and XML validator and custom Send pipeline with flat file assembler.

I am taken input an .xml file and converting it to .txt file using FILE adapters for both sending and receiving.

I want that my output file should display the name of one of my input schema's child field element value.

Pls tell me where i am getting wrong and what is the solution?

Please if you can mail me at: g12garg@gmail.com

Looking for solution
Thank you
Gaurav Garg
12/16/2006 2:27 AM | Gaurav Garg
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

Hi,
I am not using any orchestrations just receive port and send port to send a file accross. I need to rename the file with todays date only not a time stamp. Eg DD_MM_YYYY_Filename.txt How do I do that. I tried
%Date%_%SourceFileName% . No Luck.
Please advise.

Many Thanks
Sovana
1/16/2007 5:02 PM | Sovana Shrestha
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

You might want to take a look at the File Name Macros in the help guide. I don’t think Date is just called “Date”. That might be the problem.

Otherwise, you can always set the SourceFileName inside a custom pipeline component.
1/17/2007 7:03 AM | Stephen W. Thomas
Gravatar

# re: Naming Output Files in an Orchestration in BizTalk 2004

This applies to Biztalk 2006-R2

To extract the filename without the path from the incoming message and assign it to a new message, in an expression shape, do the following:

NewMessage(FILE.ReceivedFileName) = System.IO.Path.GetFileName(yourmsg(FILE.ReceivedFileName));

On the sendport, use the macro %SourceFileName% as filename.
9/25/2009 2:51 AM | Robert C
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: