Hi, all. I thought this was easy, but it's not happening.
I just want to write some text to a stream in memory. Here is my code. No matter when I check the stream length, it is always zero. What is wrong?
Gather or post content for free.
I just want to write some text to a stream in memory. Here is my code. No matter when I check the stream length, it is always zero. What is wrong?
Code:
string opfHeader = "--- Header text ---"; Stream opfStream = new MemoryStream();
long x = 0;
using (StreamWriter sw = new StreamWriter(opfStream))
{
sw.WriteLine(opfHeader);
x = opfStream.Length;
for (int i = 0; i < 10; i++)
{
string line = i.ToString();
sw.WriteLine(line);
}
x = opfStream.Length;
x = sw.BaseStream.Length;
}
Gather or post content for free.