I have a web page which I want people to be able to upload content to. (There will only be a small number of people using it, as it is access restricted, so I'm not too worried about any DOS type attacks.)
I'm using a fileUpload control to do this:
protected void Button1_Click(object sender, EventArgs e)
{
if (fileUploader.HasFile)
try {
fileUploader.SaveAs(Server.MapPath("Uploads\\") + fileUploader.FileName);
errorMessage.Text = "File name: " +
fileUploader.PostedFile.FileName + "<br>" +
fileUploader.PostedFile.ContentLength + " kb<br>";
}
catch (Exception ex) {
errorMessage.Text = "ERROR: " + ex.Message.ToString();
}
else
{
errorMessage.Text = "You have not specified a file.";
}
}
The files can be up to 50MB (I have changed the web.config to allow this). The problem I have is that with large files the user can't see the progress of the upload.
I want to know how I can display the progress on the page so the user can see something is happening. Not fussed about anything fancy - just something like:
bytes uploaded / total bytes
would be fine. I can get the total bytes using postedFile.ContentLength, but don't know how to get the bytes uploaded.
Also - am I able to refresh the screen as the upload is taking place?
Cheers,
Ben