Problem with System.Net.WebClient.OpenWrite

  • Thread starter Thread starter Sven Putze
  • Start date Start date
S

Sven Putze

my target:

I want to upload a file via HTTP Post and show the user a
progress bar

my 1st try:

I´ve used WebClient.UploadFile and WebClient.UploadData,
they work fine but I don't know any way to get the actual
amount of transferred bytes, so what should I show on the
progressbar?

my next try:

Ok, I use WebClient.OpenWrite now (so i can transfer
little blocks and then show the progress), creating the
MIME-headers was not that hard and in my home-LAN
everything seems to work fine.

my problem:

When I transfer data to the internet the Write-method
returns to fast (although it should by synchronous), so I
send the next block and so on. When the progressbar nearly
reaches 100% (depending on file size), my program freezes
and on my Network data is still sent (OK, no wonder that
sending 2MB over 128kbs upstream doesn't happen in 5
seconds).
When the file is small enough, it reaches the website.
When it's too big I get an exception (some kind of buffer
overflow I guess).

my questions:

why does the write method return still sending data?

how can I get the Information if data was really sent?

Is there an asynchronous way to do it?

Thank you
regards
Sven
 
Using the class System.Net.WebClient was not a good idea,
because it's a buffered stream.
System.Net.Sockets.NetworkStream is a better way of
dealing with my problem. I must include the HTTP-headers
and everthings works fine.

regards
Sven
 
Back
Top