coconet
4/15/2008 8:46:00 PM
I think I have one too many streamwriters. Can you sample-code that
out?
On Tue, 15 Apr 2008 13:42:34 -0700, "Peter Duniho"
<NpOeStPeAdM@nnowslpianmk.com> wrote:
>On Tue, 15 Apr 2008 13:26:05 -0700, coconet <coconet@community.nospam>
>wrote:
>
>> .NET 3.5
>> I have an HttpWebResponse.GetReponseStream() that I iterate over. Well
>> now it looks like I'll have to iterate over it twice. And that type of
>> stream does not support Seek() back to the beginning.
>>
>> So I'd like to copy it to a MemoryStream and instead iterate over that
>> two times. Can anyone show how that'd be possible?
>
>It's as simple as creating a new MemoryStream instance, reading data from
>your response Stream, writing each chunk of data as you read it into the
>MemoryStream, until you reach the end of the response Stream.
>
>Assuming the stream is reasonably short, this should be fine. You could
>in fact write out to the MemoryStream as you're processing the response
>Stream the first time, and then only read the MemoryStream one more time.
>This could be slightly more efficient, and would allow your first
>iteration of the stream to happen immediately rather than being delayed
>until the original stream has fully completed. But otherwise, it's
>probably reasonable to just make your initial processing of the original
>stream create the MemoryStream only, and then iterate that stream twice.
>
>For longer data, you're not going to want to use MemoryStream. In that
>case, you might consider getting a temporary filename from the Path class
>(Path.GetTempFileName), and using it for a FileStream instead. Same basic
>idea applies though.
>
>Pete