Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, I'm doing some stuff with WebResponse and its response stream. I've created a wrapper class that copies the stream into its own stream so that it can be able to seek through the stream.

 

I accomlish that by creating StreamWriter which writes data from the original stream to my stream. However, if I close the StreamWriter at the end, it also closes the underlying stream. Nobody can take that stream and read it then.

So, is it ok to let the StreamWriter open so that the stream also stays open?

 

Thanks

Ilya
  • Leaders
Posted

Yes. :)

You can set the stream to seek back to the beginning if you need to read the stream again.

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted
Yes. :)

You can set the stream to seek back to the beginning if you need to read the stream again.

 

Hm, maybe I'm missing something, but this code causes an ObjectDisposedException with message 'Cannot access a closed Stream'.

 

MemoryStream memoryStream = new MemoryStream();
StreamWriter streamWriter = new StreamWriter(memoryStream);
streamWriter.Write("Some data.");
streamWriter.Close();
memoryStream.Seek(0,SeekOrigin.Begin);

Ilya

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...