1

so i am making a file upload. I have, in my web.config:
<httpRuntime executionTimeout="300" maxRequestLength="5120"/>
so the file can't exceed 5MB.
My server side code looks something like:

protected void button_Click(object sender, EventArgs e) {
try {

    if (fupCV.FileName != "") {
     DirectoryInfo di = new DirectoryInfo(Server.MapPath("CVs"));
     if (!di.Exists)
         di.Create();
     fupCV.SaveAs(di.FullName + "/" + fupCV.FileName);
     //afterwards code    
    }                    
}
catch (HttpException ex) {
    Response.Write(ex.Message);                
} 

}

and i can't catch the exception, i still get "Server Error in '/' Application."

Thanx for the help

2 Answers 2

1

That's because the request never reach your code, IIS never passes the request to your code because it is to big.

I guess the only thing you can do is to upload via ajax and control the error code returned from your server.

Sign up to request clarification or add additional context in comments.

4 Comments

that's what i thought, so how can i control that the user doesn't put a file bigger than 5MBs?
You just can't ! I guess the only thing you can do is to upload via ajax and control the error code returned from your server.
well, now that some time has passed, and a miraculous solution hasn't come, i will accept your answer. Thanx
@André : I know why no miraculous solution has come up : ain't any ! Cheers
0

well, after stopping thinking about this, the answer came to my mind. I can set a bigger maxRequestLength in the web.config, say like 20 MBs if i want a limit of 5 MBs. And then in the submit event, after testing if the file is in the server, i can test it's size with

fupCV.FileBytes.Length

and throw an exception if it exceeds 5.000.000 bytes or so.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.