ilya2 Posted July 23, 2004 Posted July 23, 2004 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 Quote Ilya
Leaders Iceplug Posted July 26, 2004 Leaders Posted July 26, 2004 Yes. :) You can set the stream to seek back to the beginning if you need to read the stream again. Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
ilya2 Posted July 27, 2004 Author Posted July 27, 2004 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); Quote Ilya
Administrators PlausiblyDamp Posted July 27, 2004 Administrators Posted July 27, 2004 Closing the StreamWriter will also close it's underlying Stream - you will be getting the error when you try to seek on the underlying MemoryStream. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.