Archive for the '.NET' Category

May 28 2008

Convert String to Stream in .NET

Published by admin under .NET, Streams, Strings

You can convert a string into Stream using the following code lines.
Well, if the string is comparatively long, it’s possible use other few approaches or
to read data in small chunks and write subsequently.

MemoryStream memStream = new MemoryStream();
byte [] data = Encoding.Unicode.GetBytes(theString);
memStream.Write(data, 0, data.Length);
memStream.Position = 0;

Probably, you may like to use this stream instance to load the content as XmlDocument most of the times.

e.g. XPathDocument doc = new XPathDocument(memStream);

No responses yet