woensdag 9 mei 2012

Place root element in filename

To be able to see what type of message is in a file coming out of BizTalk, I created an encoding pipeline that includes the root element in the name of the file. Here is the execute method that I used.
/// <summary>
/// IComponent.Execute method is used to initiate the processing of the message in 
/// this pipeline component.
/// </summary>
/// <param name="pc">Pipeline context.</param>
/// <param name="inmsg">Input message.</param>
/// <returns>Original input message.</returns>
public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(IPipelineContext pc, 
    IBaseMessage pInMsg)
    // Create a new XML document
    XmlDocument xmlDocument = new XmlDocument();
    // Get the XML data from the message

    // Set the filename, starting with the root element, and adding a GUID to make
    // sure the filename is unique
    string filename = String.Format("{0}-{1}.xml", 
        xmlDocument.DocumentElement.LocalName, Guid.NewGuid()).ToUpperInvariant();

    // To be able to use the filename in the BizTalk file adapter properties, we
    // promote ReceivedFileName
    // This gives us the %SourceFileName% parameter we can use as the filename for
    // the file adapter
    // Go back to the start of the message
    pInMsg.BodyPart.Data.Position = 0;
    // Continue processing the message
    return pInMsg;

Geen opmerkingen:

Een reactie plaatsen