Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7646159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:08:14+00:00 2026-05-31T10:08:14+00:00

I have created a custom pipeline component which transforms a complex excel spreadsheet to

  • 0

I have created a custom pipeline component which transforms a complex excel spreadsheet to XML. The transformation works fine and I can write out the data to check. However when I assign this data to the BodyPart.Data part of the inMsg or a new message I always get a routing failure. When I look at the message in the admin console it appears that the body contains binary data (I presume the original excel) rather than the XML I have assigned – see screen shot below. I have followed numerous tutorials and many different ways of doing this but always get the same result.

Binary Returned

My current code is:

public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
    {


        //make sure we have something
        if (inmsg == null || inmsg.BodyPart == null || inmsg.BodyPart.Data == null)
        {
            throw new ArgumentNullException("inmsg");
        }

        IBaseMessagePart bodyPart = inmsg.BodyPart;

        //create a temporary directory
        const string tempDir = @"C:\test\excel";
        if (!Directory.Exists(tempDir))
        {
            Directory.CreateDirectory(tempDir);
        }

        //get the input filename
        string inputFileName = Convert.ToString(inmsg.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties"));


        swTemp.WriteLine("inputFileName: " + inputFileName);

        //set path to write excel file
        string excelPath = tempDir + @"\" + Path.GetFileName(inputFileName);
        swTemp.WriteLine("excelPath: " + excelPath);

        //write the excel file to a temporary folder  
        bodyPart = inmsg.BodyPart;
        Stream inboundStream = bodyPart.GetOriginalDataStream();
        Stream outFile = File.Create(excelPath);
        inboundStream.CopyTo(outFile);
        outFile.Close();

        //process excel file to return XML
        var spreadsheet = new SpreadSheet();
        string strXmlOut = spreadsheet.ProcessWorkbook(excelPath);

        //now build an XML doc to hold this data
        XmlDocument xDoc = new XmlDocument();
        xDoc.LoadXml(strXmlOut);

        XmlDocument finalMsg = new XmlDocument();
        XmlElement xEle;
        xEle = finalMsg.CreateElement("ns0", "BizTalk_Test_Amey_Pipeline.textXML",
                                      "http://tempuri.org/INT018_Workbook.xsd");
        finalMsg.AppendChild(xEle);

        finalMsg.FirstChild.InnerXml = xDoc.FirstChild.InnerXml;

        //write xml to memory stream
        swTemp.WriteLine("Write xml to memory stream");
        MemoryStream streamXmlOut = new MemoryStream();
        finalMsg.Save(streamXmlOut);
        streamXmlOut.Position = 0;


        inmsg.BodyPart.Data = streamXmlOut;
        pc.ResourceTracker.AddResource(streamXmlOut);


        return inmsg;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:08:15+00:00Added an answer on May 31, 2026 at 10:08 am

    Here is a sample of writing the message back:

        IBaseMessage Microsoft.BizTalk.Component.Interop.IComponent.Execute(IPipelineContext pContext, IBaseMessage pInMsg)
            {
                IBaseMessagePart bodyPart = pInMsg.BodyPart;          
    
     if (bodyPart != null)
                {      
    using (Stream originalStrm = bodyPart.GetOriginalDataStream())
                    {
                        byte[] changedMessage = ConvertToBytes(ret);
                        using (Stream strm = new AsciiStream(originalStrm, changedMessage, resManager))
                        {
                            // Setup the custom stream to put it back in the message.
                            bodyPart.Data = strm;
                            pContext.ResourceTracker.AddResource(strm);
                        }
                    }
                }
         return pInMsg;
    }
    

    The AsciiStream used a method like this to read the stream:

    override public int Read(byte[] buffer, int offset, int count)
            {
                int ret = 0;
                int bytesRead = 0;
    
                byte[] FixedData = this.changedBytes;
    
                if (FixedData != null)
                {
                    bytesRead = count > (FixedData.Length - overallOffset) ? FixedData.Length - overallOffset : count;
                    Array.Copy(FixedData, overallOffset, buffer, offset, bytesRead);
    
    
                    if (FixedData.Length == (bytesRead + overallOffset))
                        this.changedBytes = null;
    
                    // Increment the overall offset.
                    overallOffset += bytesRead;
                    offset += bytesRead;
                    count -= bytesRead;
                    ret += bytesRead;
                }
    
                return ret;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom list in SharePoint 2010 programmatically. It works fine on
I have created a custom class from a tutorial online. It works fine, but
friends, i have created custom title bar using following titlebar.xml file with code <?xml
If have created a custom role within SqlServer which I added to the db__denydatareader
I have created a custom ExpandableListAdapter and everything works properly. What I'd like to
I have created a custom tab layout which look like this,I want to make
I have created a custom AppleScript that works, and placed it in the folder:
I have created custom result class to serialize json data to xml. I want
I have created Custom User Control which contain TextBox and PasswordBox. it is binding
I have created custom component for displaying text with either Simple or Password mode,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.