user990635
user990635

Reputation: 4269

Write ConnectStream into MemoryStream

I am using this code to write the connectstream to memorystream:

        buffer = new byte[8 * 1024];

        while ((len = stream.Read(buffer, 0, buffer.Length)) > 0)
        {
            mStream.Write(buffer, 0, len);
        }

But I always get an error:

there was a problem reading this document (109)

Upvotes: 0

Views: 821

Answers (1)

Hans Passant
Hans Passant

Reputation: 942348

After the loop is completed, the MemoryStream is left positioned to the end of the stream. Reading from it isn't going to produce anything. Add:

  mStream.Position = 0;

Upvotes: 1

Related Questions