Converting non-unicode to unicode in BizTalk pipeline.

Hi All,

I am receiving a flat file and need to convert it from non unicode to unicode based on some conditions.

Below is the code for conversion , in the pipeline but its not working. Any suggestions ?



            MemoryStream mem = new MemoryStream();
            byte[] outBytes2 = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(content);
            MemoryStream memStream2 = new MemoryStream();
            memStream2.Write(outBytes2, 0, outBytes2.Length);
            memStream2.Position = 0;
            pInMsg.BodyPart.Data = memStream2;

            return pInMsg
August 28th, 2015 6:53am

I don't think a Custom Pipeline Component is required here.

Simply set the Code Page Property in your Flat File Schema to the non-unicode encoding the document is delivered as (ASCII 20127, Western-European 1252, etc.). That way the Flat File Disassembler will automatically convert from your non-unicode code page to UTF-8.

Morten la Cour

August 28th, 2015 7:21am

Thanks for you reply Morten,

I dont have any schema because no need to perform any data operation.

Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 7:29am

Hi Varun,

Please try below code,

MemoryStream mem = new MemoryStream();
byte[] outBytes2 = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(content);
mem.Write(outBytes2, 0, outBytes2.Length);
mem.Seek(0,SeekOrigin.Begin);
pInMsg.BodyPart.Data = mem;
August 28th, 2015 8:00am

Hold on...there's a bit more to this.

Do you know exactly what encoding/code page the source is coming in?

Why do you need to 'convert' it?

What about the BOM?

Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 8:25am

Hi Varun,

Try the below code it should work.

If not please post similar sample text contain the characters that your are facing.

byte[] bytesString = Encoding.UTF8.GetBytes(xmlDocument);
MemoryStream OutmemoryStream = new MemoryStream();
OutmemoryStream.Write(bytesString, 0, bytesString.Length);
OutmemoryStream.Seek(0, SeekOrigin.Begin);
pInMsg.BodyPart.Data = OutmemoryStream;
pContext.ResourceTracker.AddResource(OutmemoryStream);
return pInMsg;

Thanks, SMSVikasK

August 28th, 2015 9:52am

Hi Varun,

Try the below code it should work.

If not please post similar sample text contain the characters that your are facing.

byte[] bytesString = Encoding.UTF8.GetBytes(xmlDocument);
MemoryStream OutmemoryStream = new MemoryStream();
OutmemoryStream.Write(bytesString, 0, bytesString.Length);
OutmemoryStream.Seek(0, SeekOrigin.Begin);
pInMsg.BodyPart.Data = OutmemoryStream;
pContext.ResourceTracker.AddResource(OutmemoryStream);
return pInMsg;

Thanks, SMSVikasK

  • Proposed as answer by SMSVikasK 9 hours 47 minutes ago
Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 1:50pm

Hi Varun,

Try the below code it should work.

If not please post similar sample text contain the characters that your are facing.

byte[] bytesString = Encoding.UTF8.GetBytes(xmlDocument);
MemoryStream OutmemoryStream = new MemoryStream();
OutmemoryStream.Write(bytesString, 0, bytesString.Length);
OutmemoryStream.Seek(0, SeekOrigin.Begin);
pInMsg.BodyPart.Data = OutmemoryStream;
pContext.ResourceTracker.AddResource(OutmemoryStream);
return pInMsg;

Thanks, SMSVikasK

  • Proposed as answer by SMSVikasK Tuesday, September 01, 2015 9:20 PM
August 28th, 2015 1:50pm

Hi Varun,

Try the below code it should work.

If not please post similar sample text contain the characters that your are facing.

byte[] bytesString = Encoding.UTF8.GetBytes(xmlDocument);
MemoryStream OutmemoryStream = new MemoryStream();
OutmemoryStream.Write(bytesString, 0, bytesString.Length);
OutmemoryStream.Seek(0, SeekOrigin.Begin);
pInMsg.BodyPart.Data = OutmemoryStream;
pContext.ResourceTracker.AddResource(OutmemoryStream);
return pInMsg;

Thanks, SMSVikasK

Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 1:50pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics