![]() |
Enterprise Systems »
Microsoft BizTalk Server »
General
Beginner
Using the %SourceFileName% macro to create a custom send file name in BizTalk 2004By vish1979Using the send handler macro to create a custom send file name within BizTalk 2004 |
Windows, .NET, Visual Studio, Dev
|
||||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
This article walks through the motions of creating a custom name using the %SoursFileName% macro for send handlers within BizTalk 2004.
When working on a particular project I had to adhere to a naming convention for one of our customers for one of the data files we were sending. The convention was:
AAA_AA_NNNNNNNNN.xml
(A=alpha/N=numeric)
The number part always needed to be 9 numbers and in sequence. So for ease a database table is used to record each time a sequence number is created.
(The sql scripts are available with the downloadable source code.)
I then created a C# class which connects to the database to return the sequence number value.
(See downloadable source code).
I created three methods.
1 � �GetSequenceNumber�: This method (as the name suggests) uses the database methods to retrieve a new sequence number.
2 � �PadSequenceNumber�: This method returns the number of 0s to be placed in front of the sequence number returned from the database.
3 � �GetFileName�: This method is the one called in the BizTalk Orchestration to start the get the file name.
public static string GetFileName(string id) {
string num = GetSequenceNumber(id);
int i = num.Length; string name = PadSequenceNumber(i);
string res = name + num; return res;
}
For the purpose of this article I have created a simple BizTalk project which takes an address from an xml file and outputs as an xml file.
Within this project there is the address schema, the mapping between the schemas for the xml output and an orchestration for specifying the file name.

The flow of the orchestration is as follows:
Within the Message Assignment shape (after the Transform Shape) is the code that sets the file name.
//get file name
filename = BizTalk.CustomOutputFile.CSharp.Filename.GetFileName("Address");
//sets the received file name to what is specifed below
Address_Output(FILE.ReceivedFileName) = "VIS_HA_" + filename + ".xml";

As you can see the message receive name is changed. This is done using the %SourceFileName% macro available for send handlers within BizTalk 2004.
See below for other macros available:
|
Macro name |
Substitute value |
|
%datetime% |
Coordinated Universal Time (UTC) date time in the format YYYY-MM-DDThhmmss (for example, 1997-07-12T103508). |
|
%datetime_bts2000% |
UTC date time in the format YYYYMMDDhhmmsss, where sss means seconds and milliseconds (for example, 199707121035234 means 1997/07/12, 10:35:23 and 400 milliseconds). |
|
%datetime.tz% |
Local date time plus time zone from GMT in the format YYYY-MM-DDThhmmssTZD, (for example, 1997-07-12T103508+800). |
|
%DestinationParty% |
Name of the destination party. The value comes from message the context property BTS.DestinationParty. |
|
%DestinationPartyID% |
Identifier of the destination party (GUID). The value comes from the message context property BTS.DestinationPartyID. |
|
%DestinationPartyQualifier% |
Qualifier of the destination party. The value comes from the message context property BTS.DestinationPartyQualifier. |
|
%MessageID% |
Globally unique identifier (GUID) of the message in BizTalk Server. The value comes directly from the message context property BTS.MessageID. |
|
%SourceFileName% |
Name of the file from where the File adapter read the message. The file name includes extension and excludes the file path, for example, foo.xml. When substituting this property, the File adapter extracts the file name from the absolute file path stored in the FILE.ReceivedFileName context property. 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%). |
|
%SourceParty% |
Name of the source party from which the File adapter received the message. |
|
%SourcePartyID% |
Identifier of the source party (GUID). The value comes from the message context property BTS.SourcePartyID. |
|
%SourcePartyQualifier% |
Qualifier of the source party from which the File adapter received the message. |
|
%time% |
UTC time in the format hhmmss. |
|
%time.tz% |
Local time plus time zone from GMT in the format hhmmssTZD (for example, 124525+530). |
I created a receive and sent port, specifying locations where I wanted the files to be dropped.
On the send port I set the File name property to
%SourceFileName%

Once I had done this, I deployed the project. Started the orchestration and dropped a test file in the location and watch it create a file name with using a sequence number.
i.e. %MessageID%+ %time%.xml
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 22 Mar 2006 Editor: |
Copyright 2006 by vish1979 Everything else Copyright © CodeProject, 1999-2009 Web09 | Advertise on the Code Project |