BizTalk Pipeline Components Extensions Utility Pack: Dynamic Set Filename based on XPath, Timestamp and Prefix

  • Sandro Pereira
  • Dec 23, 2025
  • 3 min read

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:

  1. Reads the outgoing message stream (XML).
  2. Uses an XPath query to extract a business identifier (e.g., Invoice Number, Order ID, Document Number).
  3. 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.
  4. Promotes the result to the message context under:
  5. ReceivedFileName in 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:
    • Prefix
    • XPathQuery
    • UseTimestamp

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.

BizTalk Pipeline Components Extensions Utility Pack: Unzip File Pipeline Component

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!

Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

Leave a Reply

Your email address will not be published. Required fields are marked *

The Ultimate Cloud
Management Platform for Azure

Supercharge your Azure Cost Saving

Learn More
Turbo360 Widget

Back to Top