Yes I noticed how stupid my code was, my latest code is below, feel like I'm
getting closer, but it's now acting very strange. The last
console.writeli ne returns the length of the stream has 88, but the file
which ultimatly gets created by biztalk is blank.
I've posted on the biztalk site, so maybe this isn't a C# issue anymore.
StreamReader ms = new StreamReader(in msg.BodyPart.Da ta);
MemoryStream mms = new MemoryStream();
string content = string.Empty;
content = ms.ReadToEnd();
content = content.Replace ("<cdatasection >", "<![CDATA[");
content = content.Replace ("</cdatasection>", " ]]>");
byte[] imgarray = StrToByteArray( content);
mms.Write(imgar ray,0,imgarray. Length);
inmsg.BodyPart. Data = mms;
Console.WriteLi ne(mms.Length);
Console.WriteLi ne(content);
Console.WriteLi ne("HELLO");
Console.WriteLi ne(imgarray.Len gth);
Console.WriteLi ne("LENGTH OF INMSG = ");
Console.WriteLi ne(inmsg.BodyPa rt.Data.Length) ;
return inmsg;
"Peter Bromberg [C# MVP]" <pb*******@yaho o.nospammin.com > wrote in message
news:60******** *************** ***********@mic rosoft.com...
If immsg.BodyPart. Data is a stream, what you are doing is reading it into
a
string (content). Then you are performing a string Replace on this string.
Remember, the string is a completely separate object from what was in the
stream.
So finally, you are attempting to assign "ms" which is a StreamReader, to
the BodyPart.Data object which we've already discovered is not a
StreamReader, but a Stream. Meanwhile, completely separate and distinct
from
this, you have a string, "content" - which you have altered. Does this
make
sense?
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"...." wrote:
Hi
I have an existing function which has a stream object
(inmsg.BodyPart .Data).
I'm trying to search and replace the stream object in the most efficient
way
possible
This is my attempt below, however I'm getting a message on the last line
that I can't convert a memorystream to a stream. Any hints, or better
ways
of doing this?
Thanks in advance
StreamReader ms = new StreamReader(in msg.BodyPart.Da ta);
string content = string.Empty;
content = ms.ReadToEnd();
content = content.Replace ("HELLO","GOODB YE");
content = content.Replace ("YES","NO") ;
inmsg.BodyPart. Data = ms;