I want to
limit the size of the uploaded files, and show an error if the file is bigger
than this limit.
I put the
parameter "<httpRuntime maxRequestLength="10240"
executionTimeout="300"/>" in the web.config.
The problem
is that when the file is bigger than the limit, the browser shows an error page
like "Internet Explorer can not display the webpage ..." the execution of the application stops, and do
not continue with the code that checks the upload status to show an error
message if the upload fails.
This is the
code of the Upload button:
protected void submitButton_Click(object
sender, EventArgs args)
{
UploadStatus status =
HttpUploadModule.GetUploadStatus();
if (status != null)
{
uploadPanel.Visible = false;
uploadResultsPanel.Visible = true;
ReadOnlyCollection
<UploadedFile> files;
if (status.Reason ==
UploadTerminationReason.NotTerminated)
{
resultsMessage.InnerText =
"Upload completed successfully. The following files were uploaded:";
resultsRepeater.DataSource =
status.GetUploadedFiles();
files =
status.GetUploadedFiles();
string a = files[0].ClientName;
string b;
files[0].LocationInfo.TryGetValue("fileName",out
b);
int registros = 0;
ActionProcedures.ApFicherosCongresoInsertar(((clsSession)this.Session["Idsession"]).Usuario,
idFolder, files[0].ClientName, Folder + "/" + idFolder +
"/" + b.Substring(b.LastIndexOf("\\")+1),
files[0].ContentType, 0, ref registros);
this.ClientScript.RegisterClientScriptBlock(this.GetType(),
"reload", "<script
type='text/javascript'>window.opener.reloadFiles('" + idFolder +
"');</script>");
resultsRepeater.DataBind();
}
else
{
if (status.Reason ==
UploadTerminationReason.Disconnected)
{
resultsMessage.InnerText =
"Upload was cancelled.";
}
else
{
resultsMessage.InnerHtml =
"Upload resulted in an error.<br />Reason:" +
status.Reason.ToString() + "<br />Message:" +
status.ErrorMessage;
}
resultsMessage.Style["color"] = "red";
}
}
}