Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Max request length File upload

Status
Not open for further replies.

kalkumar

Programmer
Jul 7, 2006
40
US
Hi,

In order to handle the error i.e page cannot be dsplayed when we upload file size more than 4 mb using Fileupload control: Iam writing the following code in Global.asax file:

void Application_Error(object sender, EventArgs e)

{

// Code that runs when an unhandled error occurs

// Fires when an error occurs Check to see whether we came from the upload form

string fn=System.IO.Path.GetFileName(Request.Path).ToString();

if ( fn== "default.aspx")

{

//Get error details

System.Exception appException=Server.GetLastError();

HttpException checkException=(HttpException) appException;

//Verfy the expected error

int code = checkException.GetHttpCode();



if((code==500) ||(checkException.ErrorCode==-2147467259))

{


// Error 400 = bad request, user

// tried to upload a file that's too large

Session["ImageTooLarge"] = 1;

Server.ClearError();

//Go to the original target page

Response.Redirect("default.aspx");

}

}

and in the Default.aspx page load is like this:

if (!IsPostBack)

{



// Check to see whether we were redirected from the error page

int i=Convert.ToInt32(Session["ImageTooLarge"]);

if (i==1)

{

lblTooLarge.Text = "Exceeded";



}

but still I am getting page not displayed error. When I try to debugg the Application_Error event is firing in that event it is storing 1 into session, but the page is not redirecting to Default.aspx page.

What I am doing wrong.

Thanks in advance.
 
Hi,
I tried the Server.transfer("Default.aspx") also but no use.
 
I believe there is a web.config/machine.config setting to adjust the max file size for uploaded files.

I would also suggest placing a try/catch block around the event to upload the file and handle it there instead of the global error.

there is also a file length property associated with the upload control. Depending on when the exception is thrown you may be able to check the file size. use an if/then/else statement to handel a file <= 4Mb.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Did you find the solution for this?

jmeckley...the file size isnt the problem, catching the error neither...its redirecting after the error occures to a custom page.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top