Yeah, if you need intermediate progress indications, you should upload the data asynchronously.
For that, get the stream as before..
Stream requestStream = request.GetRequestStream();
Byte [] photo = readPhotograph(..); // get the photo into a byte array. Or alternately, read from a stream.
int totalSize = photo.Length;
int offset = 0;
int totalWritten = 0;
void ReadCallback(IAsyncResult ar)
{
Stream stream = ar.AsyncState as Stream;
try
{
int written = stream.EndRead(ar);
offset += written;
totalWritten += written;
// here, update dialog box.
this.updateProgress(totalWritten, totalSize);
if (totalWritten < totalSize)
{
int chunkSize = Math.Min(1024, (totalSize-totalWritten));
// kick off another async write
stream.BeginWrite(photo, offset, chunkSize, new AsyncCallback(ReadCallback), stream);
}
}
}
The code snippet needs some work to separate out state variables, but you get the idea...
int chunkSize = Math.Min(totalSize, 1024) // write in 1k chunks.
requestStream.BeginWrite(photo, 0, chunkSize, new AsyncCallback(WriteCallback), requestStream);
in your callback...
feroze
--
My blog