469,613 Members | 1,960 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

Error in file upload

I am trying to upload a file to the webserver through my
asp.net application. The file upload works fine for files
below 50 MB size because i have set the maxrequestlength
property of the <httpruntime> in the machine.config file
as 51200KB. whenever the user tries to upload a file which
is more than 51200KB then, a blank page with DNS error is
shown as soon as the user hits the submit button.
I want to be able to display an error message to the user
if the file size is greater than 50 MB. How do i catch
this error? I have tried using the try catch block in the
submit button onClick() event, but no use. Please post me
detailed answer.
Thanks in advance.

Nov 18 '05 #1
4 2098
"Amar" <an*******@discussions.microsoft.com> wrote in message
news:0a****************************@phx.gbl...
I am trying to upload a file to the webserver through my
asp.net application. The file upload works fine for files
below 50 MB size because i have set the maxrequestlength
property of the <httpruntime> in the machine.config file
as 51200KB. whenever the user tries to upload a file which
is more than 51200KB then, a blank page with DNS error is
shown as soon as the user hits the submit button.
I want to be able to display an error message to the user
if the file size is greater than 50 MB. How do i catch
this error? I have tried using the try catch block in the
submit button onClick() event, but no use. Please post me
detailed answer.


If you are using a RUNAT=SERVER form with an <input type=file /> style
control, you really only have access to the stream of a posted file after
the file has been fully sent. What you'd have to do is permit the clients to
send files larger than the max, and then measure the file only after it has
been fully posted.

The maxrequestlength property is a bit of a security measure, and can't
really be bypassed even for file measuring purposes, not even with try/catch
blocks. For RFC 1867 uploads, I still use .asp a lot of the time, as it is a
bit more permissive about them.

Richard
Nov 18 '05 #2
Assuming you use the HTMLInputFile Control to choose your
file to upload then you can do something like this,

HttpPostedFile file = fileUpload.PostedFile;
int fileLen = file.ContentLength;

fileUpload is the HTMLInputFile control name ...

Thanks,
-Shan

-----Original Message-----
I am trying to upload a file to the webserver through my
asp.net application. The file upload works fine for files
below 50 MB size because i have set the maxrequestlength
property of the <httpruntime> in the machine.config file
as 51200KB. whenever the user tries to upload a file whichis more than 51200KB then, a blank page with DNS error is
shown as soon as the user hits the submit button.
I want to be able to display an error message to the user
if the file size is greater than 50 MB. How do i catch
this error? I have tried using the try catch block in the
submit button onClick() event, but no use. Please post me
detailed answer.
Thanks in advance.

.

Nov 18 '05 #3
Sorry didnt see Richards reply ! Richard is probably
right !

Thanks,
-Shan

-----Original Message-----
"Amar" <an*******@discussions.microsoft.com> wrote in messagenews:0a****************************@phx.gbl...
I am trying to upload a file to the webserver through my
asp.net application. The file upload works fine for files below 50 MB size because i have set the maxrequestlength
property of the <httpruntime> in the machine.config file
as 51200KB. whenever the user tries to upload a file which is more than 51200KB then, a blank page with DNS error is shown as soon as the user hits the submit button.
I want to be able to display an error message to the user if the file size is greater than 50 MB. How do i catch
this error? I have tried using the try catch block in the submit button onClick() event, but no use. Please post me detailed answer.
If you are using a RUNAT=SERVER form with an <input

type=file /> stylecontrol, you really only have access to the stream of a posted file afterthe file has been fully sent. What you'd have to do is permit the clients tosend files larger than the max, and then measure the file only after it hasbeen fully posted.

The maxrequestlength property is a bit of a security measure, and can'treally be bypassed even for file measuring purposes, not even with try/catchblocks. For RFC 1867 uploads, I still use .asp a lot of the time, as it is abit more permissive about them.

Richard
.

Nov 18 '05 #4
Thanks Richard and Shan,
I am using the HtmlInputFile control.But Shan where
exactly do you want me to put in your code? becoz,after
the user selects a file to upload and hits Submit, then
the flow of the code does not go into the OnClick() event
of the submit button, if the filesize is > 50 Mb.I checked
this by setting a breakpoint on the first line of the
OnClick event. The aspx page just shows a DNS error page.
Is there a way, that i can check the size of the file
before the user clicks submit maybe.
-----Original Message-----
Assuming you use the HTMLInputFile Control to choose your
file to upload then you can do something like this,

HttpPostedFile file = fileUpload.PostedFile;
int fileLen = file.ContentLength;

fileUpload is the HTMLInputFile control name ...

Thanks,
-Shan

-----Original Message-----
I am trying to upload a file to the webserver through my
asp.net application. The file upload works fine for filesbelow 50 MB size because i have set the maxrequestlength
property of the <httpruntime> in the machine.config file
as 51200KB. whenever the user tries to upload a file

which
is more than 51200KB then, a blank page with DNS error isshown as soon as the user hits the submit button.
I want to be able to display an error message to the userif the file size is greater than 50 MB. How do i catch
this error? I have tried using the try catch block in thesubmit button onClick() event, but no use. Please post medetailed answer.
Thanks in advance.

.

.

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Amy Kimber | last post: by
6 posts views Thread by Paul | last post: by
reply views Thread by Buddy Home | last post: by
rahulephp
4 posts views Thread by rahulephp | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.