One of the most common “small” requirements in BizTalk projects is also one of the most annoying to keep consistent: outbound file naming.
You need filenames that:
- match a partner specification,
- include a meaningful business key from the payload,
- and (almost always) include a timestamp to avoid collisions.
Dynamic Set Filename based on XPath, Timestamp, and Prefix Pipeline Component
Instead of implementing this logic in every orchestration or mapping layer, you can centralize it in a custom send pipeline component that extracts a value from the message body using XPath, builds a filename, and promotes ReceivedFileName so the FILE or (S)FTP adapter’s uses it as the outbound name.
This is a send pipeline component that you can place in any stage of a send pipeline (commonly Encode or Pre-Assemble).
When the message is being sent, the component:
- Reads the outgoing message stream (XML).
- Uses an XPath query to extract a business identifier (e.g., Invoice Number, Order ID, Document Number).
- Builds a filename like:
PREFIX<BusinessId>.xml- or
PREFIX<BusinessId>-2025-12-22T214455.xml(when timestamp is enabled) - The PREFIX and the Timestamp are optional.
- Promotes the result to the message context under:
ReceivedFileNamein the namespace:http://schemas.microsoft.com/BizTalk/2003/file-properties
This is the key detail: the FILE or (S)FTP adapter’s uses ReceivedFileName as the output filename when writing to disk/share.
The pipeline component code
Here’s the core logic:
public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(
Microsoft.BizTalk.Component.Interop.IPipelineContext pContext,
Microsoft.BizTalk.Message.Interop.IBaseMessage pInMsg)
{
string filename = string.Empty;
//get the message data
IBaseMessagePart bodyPart = pInMsg.BodyPart;
Stream originalStream = pInMsg.BodyPart.GetOriginalDataStream();
try
{
XmlDocument ediXml = new XmlDocument();
ediXml.Load(originalStream);
XmlNode xNode = ediXml.SelectSingleNode(this.XPathQuery);
filename = Prefix + xNode.InnerText;
if (UseTimestamp)
filename += "-" + DateTime.Now.ToString("yyyy-MM-ddTHHmmss") + ".xml";
else filename += ".xml";
}
catch
{
filename += Prefix + DateTime.Now.ToString("yyyy-MM-ddTHHmmss") + ".xml";
}
finally
{
originalStream.Seek(0, SeekOrigin.Begin);
originalStream.Position = 0;
bodyPart.Data = originalStream;
}
pInMsg.Context.Promote(
"ReceivedFileName",
"http://schemas.microsoft.com/BizTalk/2003/file-properties",
filename);
return pInMsg;
}
How to use it in a Send Pipeline
- Deploy the component assembly to the BizTalk servers.
- Add the component to a custom Send Pipeline in Visual Studio.
- Deploy the custom pipelines to the BizTalk Servers
- Assign that send pipeline to your FILE send port.
- Configure the component properties:
PrefixXPathQueryUseTimestamp
Once it’s in place, every message that goes through that port gets a predictable name without needing orchestration logic.
What is BizTalk Pipeline Components Extensions Utility Pack?
The BizTalk Pipeline Components Extensions Utility Pack is a set of custom pipeline components (libraries) with several custom pipeline components that can be used in received and sent pipelines, which will provide an extension of BizTalk’s out-of-the-box pipeline capabilities.
The project is available on the BizTalk Server Open Source Community repository on GitHub (https://github.com/BizTalkCommunity), and everyone can contribute new pipeline components that can extend or improve the existing BizTalk Server capabilities.

At the moment, it is only available for BizTalk Server 2020, but it can be easily converted and compiled for earlier versions of the product.
Where to download it?
You can download BizTalk Pipeline Components Extensions Utility Pack from GitHub here:
Hope you find this helpful! If you enjoyed the content or found it useful, and wish to support our efforts to create more, you can contribute to purchasing a Star Wars Lego set for my son!