Hi.
I have successfully designed a large file upload method using WCF. Now, I would like to report progress for each unique file being loaded. In my upload method, i have the following code block:
while ((bytesRead = request.FileByteStream.Read(buffer, 0, bufferSize)) > 0)
{
outfile.Write(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
if (this.ProgressChanged != null)
this.ProgressChanged(this, new ProgressArgs(totalBytesRead, request.FileByteStream.Length));
}
Which uses the deleget ProgressEventHandler as declared below:
public delegate void ProgressEventHandler(object sender, ProgressArgs e);
public event ProgressEventHandler ProgressChanged;
I do not use delegates all that much (but am trying to learn) and got this far by
following examples online. The class ProgressArgs was missing from the example but
I am guessing that is where the calculation takes place and is returned? Something
like: return Convert.ToInt32((totalBytesRead * 100) / fileSize)
?
So, my questions are thus:
1) Assming I have declared and called my ProgressChanged event correctly, what do I
do with ProgressArgs?
2) How do I report progress back to the client? My WCF method call currently has a 'void' return type:
upload.UploadFile(fileinfo, m_objFile.InputStream);
Will I need to fire a simultaneous JavaScript method that calls a WCF JSON method or something of that nature? A detailed explanation of how to view progress from the client would be seriously appreciated.
Thanks!
PS - I am using ASP.NET 2.0 / Framework 3.5 / C# / and I am self-hosting currently.