Aug 232008
 

I’ve needed to cast my BizTalk message as a System.String in a couple of occasions so I’m going to put it here to remember how to do it.
1. Create a Variable of type System.Xml.XmlDocument (I’m calling it xml_Temp here)
2. Create a Variable of Type string (I’m calling it str_MessageAsString here)
3. In the expression shape insert the following code:

//Instantiate your xml_Temp System.Xml.XmlDocument
xml_Temp = new System.Xml.XmlDocument();
//Assign the message you want as a string to your new xml_Temp System.Xml.XmlDocument
xml_Temp = msg_YourOriginalMessage;
//Assign the .OuterXml property of your xml_Temp to your str_MessageAsString System.String
str_MessageAsString = xml_Temp.OuterXml;

  • Christian Heusbourg

    Hi Eric,

    a helper class like the one bellow is more efficient to turn a BizTalk msg to a string.

    Cheers,
    Christian.

    public static string GetStringFromBTSMsgBody(XLANGMessage btsMessage)
    {
    string result;
    StreamReader reader = new StreamReader((Stream)btsMessage[0].RetrieveAs(typeof(Stream)));
    result = reader.ReadToEnd();
    reader.Close();
    return result;
    }

  • Thanks Christian.
    Nice code snippet!

    Eric