As far as I know, you can not write and read from the same
MemoryStream. You have to grab the contents as a byte array and create
a new MemoryStream to read from. You also need to call Flush on the
CsvWriter, which will in turn call Flush on the internal StreamWriter
which buffers by default. I tried just adding the Flush call to your
sample code and I still got the empty string. The code below does
output a string.
using (MemoryStream foMS = new MemoryStream())
using (CsvWriter foCSVWrite = new CsvWriter(foMS, ',',
Encoding.ASCII))
{
foCSVWrite.Write("hello");
foCSVWrite.Flush();
using (MemoryStream foMSRead = new MemoryStream(foMS.ToArray()))
using (StreamReader foCsvRead = new StreamReader(foMSRead,
Encoding.ASCII))
{
string fsMystr = foCsvRead.ReadToEnd();
Console.WriteLine(fsMystr);
Console.ReadLine();
}
}
Bruce Dunwiddie