Geeks With Blogs
Bill Osuch - Random geek notes

By default, BizTalk creates the filename of the message dropped to a send port as %MessageID%, which is the unique identifier (GUID) of the message. What if you want to create your own filename?

To start, create a simple schema, and a basic orchestration that will receive the message and send it right back out, like this:

If you deploy this and wire up the ports, you can drop an xml file into your receive port and have it come out at your send port named something like {7A63CAF8-317B-49D5-871F-9FD57910C3A0}.xml.

Now, we'll create a new message with a custom filename. First, create a new orchestration variable called NewFileName, of the type System.String. Next, create a second message using the same schema as the message you're receiving in the Receive shape.

Now, drag a Construct Message shape to the orchestration. In the shape's properties, set Messages Constructed to be the new message you just created. Double click the Message Assignment shape (inside the Construct shape...) and paste in the following code:

Message_2 = Message_1;
NewFileName = Message_1(FILE.ReceivedFileName);
NewFileName = NewFileName.Replace(".xml","_");
NewFileName = NewFileName + "output_" + System.DateTime.Now.Year.ToString() + "-" + System.DateTime.Now.Month.ToString();
Message_2(FILE.ReceivedFileName) = NewFileName;

Here we make a copy of the received message, get it's original file name (ReceivedFileName), replace its extension with an underscore, and date-stamp it.

Finally, add a Send shape and a Port to the surface, and configure them to send the message you just created. You should wind up with an orchestration like this:

Deploy it, and create a new send port. It should be just about identical to the first send port, except this time the file name will be "%SourceFileName%.xml" (without the quotes of course).

Fire up the application, drop in a test file, and you should now get both the xml file named with a GUID, and a second file named something along the lines of "MySchemaTestFile_output_2011-6.xml".

Technorati Tags:

Posted on Friday, June 24, 2011 2:40 PM BizTalk | Back to top

Comments on this post: Changing the BizTalk message output file name

# re: Changing the BizTalk message output file name
Requesting Gravatar...
Hi Bill,

Thanks for the blog. It was a good starter to Orchestration but I have difficulty in getting it working. I'm using BizTalk 2010 and a simple configuration

Goal: Transform the message from one format to another and write the output file in a custom format - SourceParty_MMDDYY.XML

Constraint: The source file name should not be modified

Receive Port
Receieve Shape
Construct Message
Transform Shape
Message Assignment
Send Shape
Send Port

I/P message: Mesg1
O/P message: Mesg2

In the MessageAssignment, the expression used is
fileName = Mesg1(BTS.SourceParty);
fileName = fileName + System.DateTime.Now.ToString();
Mesg2(FILE.ReceivedFileName) = fileName;

In the Send Port, output file is configured as '%SourceFileName%.xml'

For a input file(Message1.txt)The transformation works fine but it always generates the output file as 'Message1.xml'.

I see that the "%SourceParty%".xml works for BizTalk 2004 and not for BizTalk 2010.

Can you please tell me if BizTalk 2010 works differently?
Left by Sandeep on Jan 15, 2013 12:54 PM

# re: Changing the BizTalk message output file name
Requesting Gravatar...
I haven't worked with BTS.SourceParty, so I don't know the exact cause of this... Are you sure the party resolution is working properly? Maybe try suspending the message (by disabling the subscriber) and verify the context properties.
Left by Bill on Jan 16, 2013 9:20 AM

Your comment:
 (will show your gravatar)

Copyright © Bill Osuch | Powered by: