Changing the BizTalk message output file name

Posted by Bill Osuch on Geeks with Blogs See other posts from Geeks with Blogs or by Bill Osuch
Published on Fri, 24 Jun 2011 19:40:59 GMT Indexed on 2011/06/25 0:23 UTC
Read the original article Hit count: 440

Filed under:

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".

© Geeks with Blogs or respective owner