473,386 Members | 1,785 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,386 software developers and data experts.

Uploading file problem

Hi everyone,
I have a problem with the file uploading in Asp.Net and I have read a lot
on forums on this but never found an answer. Here is the problem:

I know Asp.Net maximum Length for uploading a file to the server is 4Mo
but I changed that maximum to about 10Mo in my web.config file :

<httpRuntime executionTimeout="45" maxRequestLength="10000"
useFullyQualifiedRedirectUrl="true" />

Now, if i upload a 5Mo file to the server their won't be any problem but
if i upload a 12Mo file to the server, then i get to a File Not found
page. Even if i try to verify my length of file, i get an error. In this
example, the maximum the user can upload is 1Mo even if the
maxRequestLength in my Web.config file is set to 10Mo. Here is some code:

Dim intMaxLength As Integer = "1000000" 'bytes

If fil_Upload.PostedFile.ContentLength < intMaxLength Then
'Save uploaded file to server
Try
fil_Upload.PostedFile.SaveAs(Server.MapPath(".\myp ath\" &
strFormatedName))
lab_Confirmation.ForeColor = System.Drawing.Color.Black
lab_Confirmation.Text = "Success"
Catch Exp as exception
lab_Confirmation.ForeColor = System.Drawing.Color.Red
lab_Confirmation.Text = "Error"
End Try
End If

If i had set my maxRequestLength to "5000" (5Mo) then every time i would
try to upload a file that is bigger then 5Mo, i would be redirected to a
File Not Found page (even if i have a length verification of under 1Mo!)

So, is there any way to prevent the user to try to upload a 60Mo,
70 Mo, 80Mo file to the server without having to set my maxRequestLength
to "60000","70000", "80000" and having to validate my ContentLength
before it is uploaded. In other words, can i set my maxRequestLength to
some maximum length and verify it before uploading the file to the
server.

Any help, article, thread, example, code, explanation is appreciated.

Thanx in advance.

Jonathan
Jul 21 '05 #1
1 2171
No, when you click the submit button, the file is always uploaded to the
server, regardless of the size. There is actually no point in checking the
file size within your code because it never gets that far if the size is too
large. ASP.NET is actually what checks the size of the file and will stop
the upload if the content is too much.

If your code runs, you are guaranteed that the file smaller then the
maximum.
"Jonathan" <aa*@aaa.com> wrote in message
news:Xn***********************@206.167.113.5...
Hi everyone,
I have a problem with the file uploading in Asp.Net and I have read a lot
on forums on this but never found an answer. Here is the problem:

I know Asp.Net maximum Length for uploading a file to the server is 4Mo
but I changed that maximum to about 10Mo in my web.config file :

<httpRuntime executionTimeout="45" maxRequestLength="10000"
useFullyQualifiedRedirectUrl="true" />

Now, if i upload a 5Mo file to the server their won't be any problem but
if i upload a 12Mo file to the server, then i get to a File Not found
page. Even if i try to verify my length of file, i get an error. In this
example, the maximum the user can upload is 1Mo even if the
maxRequestLength in my Web.config file is set to 10Mo. Here is some code:

Dim intMaxLength As Integer = "1000000" 'bytes

If fil_Upload.PostedFile.ContentLength < intMaxLength Then
'Save uploaded file to server
Try
fil_Upload.PostedFile.SaveAs(Server.MapPath(".\myp ath\" &
strFormatedName))
lab_Confirmation.ForeColor = System.Drawing.Color.Black
lab_Confirmation.Text = "Success"
Catch Exp as exception
lab_Confirmation.ForeColor = System.Drawing.Color.Red
lab_Confirmation.Text = "Error"
End Try
End If

If i had set my maxRequestLength to "5000" (5Mo) then every time i would
try to upload a file that is bigger then 5Mo, i would be redirected to a
File Not Found page (even if i have a length verification of under 1Mo!)

So, is there any way to prevent the user to try to upload a 60Mo,
70 Mo, 80Mo file to the server without having to set my maxRequestLength
to "60000","70000", "80000" and having to validate my ContentLength
before it is uploaded. In other words, can i set my maxRequestLength to
some maximum length and verify it before uploading the file to the
server.

Any help, article, thread, example, code, explanation is appreciated.

Thanx in advance.

Jonathan

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dickiedyce | last post by:
Hi there. I've spent the weekend getting ever more frustrated, trying to get an upload file function working on a website. The site is hosted by a company called oneandone. They're using PHP...
5
by: Kevin Ollivier | last post by:
Hi all, I've come across a problem that has me stumped, and I thought I'd send a message to the gurus to see if this makes sense to anyone else. =) Basically, I'm trying to upload a series of...
3
by: Mike | last post by:
Hi i have a problem in asp.ne i am uploading file to the server using htmlinput controls and every thing is o but i try to upload larger file to the server like more than 4 mb and about 10mb i got...
5
by: Ron Brennan | last post by:
Good afternoon. The entire task that I'm trying to achieve is to allow a user to browse and upload multiple files simultaneously, hiding the Browse button of <input> tags of type="file" and...
3
by: Jason Chu | last post by:
I've written a file uploading part of my application using the IHttpModule. So now, I don't have the memory problem of uploading something big. Problem: I can't find which function I have to...
1
by: Jonathan | last post by:
Hi everyone, I have a problem with the file uploading in Asp.Net and I have read a lot on forums on this but never found an answer. Here is the problem: I know Asp.Net maximum Length for...
1
by: wenqiang7 | last post by:
I am encountering a very strang problem with file uploading in my ASP.Net page. When we try to upload certain file, we'll get an error msg of "Cannot find server or DNS Error". We are running...
3
ganesanji
by: ganesanji | last post by:
hi all, I have written a php coding for uploading a file to a specific folder or location in server which is a Linux server. I think the coding for file uploaing is correct. But it does not...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.