Well, you can create your own Exception that would inherit from the base Exception class. That would have the text and a name that would tell the user that this is bad - well, it will tell him what went wrong.
For creating customs, you can read
this document[
^].
It will be like this,
using System;
public class FileTooLargeException : Exception {
public FileTooLargeException () {
}
}
.. then call it using that statement.
However, you can also pass a simple string to the Exception to remove the
blank-ness of it as this one,
throw new Exception("Maximum file size is 5mb.");
.. this one would be more like it. Did you try?
While I was out, I was working on this answer - you can throw an HttpException that is present inside the System.Web. Use this HttpException instead of that Exception in my second code block and it will be the
HttpException[
^] in your application.
Somehow, there is a web.config file (since you're working with ASP.NET) where you can yourself specify the maximum size for the uploaded file. If you specify the size there, it will help you to focus on the logic only and the ASP.NET will take care of the remaining stuff itself. It is to be written like this,
<configuration>
<system.web>
<httpRuntime maxRequestLength="xxx" />
</system.web>
</configuration>
.. these are a few methods that you can use in this scenario. :-)