By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,587 Members | 1,891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,587 IT Pros & Developers. It's quick & easy.

Uploading file problem

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.