473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 2271
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Amy Kimber | last post by:
Hello, I have a file upload page, and I've had it working fine, it was beautiful :-) Anyway, the powers that be moved hosts... and it doesn't work now. The file name is correct, the directory...
7
by: Joe | last post by:
I have an upload file operation in the web application. UploadForm.asp is the form, and UploadAction.asp is the form processing. //UploadForm.asp <FORM NAME="InputForm"...
6
by: Paul | last post by:
Hi there, When adding a "File Field" HTML control to an aspx page to facilitate file uploading, the following occurs: 1. You select a file that is larger than the allowed size limit. 2. Once...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
2
by: Paolo | last post by:
Hi to all, I have an error that drove me crazy. Try the following page that should only allow to upload a file: <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
1
by: chrisj | last post by:
I'm using freeASPupload and got some assistance integrating to a Member script. It works successfully. In this modified version there are two groups that use this upload script. Members of one...
4
rahulephp
by: rahulephp | last post by:
i think i am missing something in the below script: It shows error an do not upload files to destination: Let me know how to solve this: <?php if (isset($_POST)) { $uploadArray=...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.