472,143 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 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 2056
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by dickiedyce | last post: by
5 posts views Thread by Kevin Ollivier | last post: by
3 posts views Thread by Jason Chu | last post: by
1 post views Thread by Jonathan | last post: by
1 post views Thread by wenqiang7 | last post: by
ganesanji
3 posts views Thread by ganesanji | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

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.