WebClient and WebResponse eats up memory

  • Thread starter Thread starter ScottO
  • Start date Start date
S

ScottO

How can I upload a file to a ASP.NET page without having the stream eating
up memory without using a 3rd party component?

How can I download a file from a different webpage without eating up memory
without using a 3rd party component?

Files that are just under 2 Gig.

Using FTP is not an option.

Using WebClient.DownloadData and WebResponse.GetResponseStream appear to
both eat up CPU and memory.

Thanks in advanced for the advice,

Scott
 
ScottO,

To upload and download the file, you should be using HttpWebRequest and
HttpWebResponse. Both of them use a stream to get the data to/from the
server, which should reduce the overall working set that you would use. If
you use WebClient, it is going to return everything in an array at one time,
and for large files, like you have noticed, it can be a real
performance-killer.

You should use GetResponseStream, and read in chunks from the stream,
processing them as you read them.

Hope this helps.
 
Many thanks Nicholas. I will try it and let you know how it turns out...

Nicholas Paldino said:
ScottO,

To upload and download the file, you should be using HttpWebRequest and
HttpWebResponse. Both of them use a stream to get the data to/from the
server, which should reduce the overall working set that you would use. If
you use WebClient, it is going to return everything in an array at one time,
and for large files, like you have noticed, it can be a real
performance-killer.

You should use GetResponseStream, and read in chunks from the stream,
processing them as you read them.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

ScottO said:
How can I upload a file to a ASP.NET page without having the stream eating
up memory without using a 3rd party component?

How can I download a file from a different webpage without eating up memory
without using a 3rd party component?

Files that are just under 2 Gig.

Using FTP is not an option.

Using WebClient.DownloadData and WebResponse.GetResponseStream appear to
both eat up CPU and memory.

Thanks in advanced for the advice,

Scott
 
Back
Top