Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / October 2004

Tip: Looking for answers? Try searching our database.

Uploading file problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jonathan - 27 Oct 2004 19:58 GMT
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(".\mypath\" &    
    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
Peter Rilling - 27 Oct 2004 21:55 GMT
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.

> Hi everyone,
> I have a problem with the file uploading in Asp.Net and I have read a lot
[quoted text clipped - 43 lines]
>
> Jonathan

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.