Error In file upload using ASP.NET

Shims

Active member
Joined
Jun 15, 2003
Messages
39
I am using an asp.net page that allows an upload of plain text files to the server. Everything works great, except every time i want to upload a file over 5 megs, i get a "cannot display webpage" error. this is the code I am using:
Code:
Dim file As HttpPostedFile
        Dim dateinfo As String
        Dim root As String
        Dim strfilename As String

        dateinfo = "(" & DateTime.Now.Date.Month & "-" & DateTime.Now.Date.Day & "-" & DateTime.Now.Date.Year & ")" & " [hr" & DateTime.Now.Hour & " min" & DateTime.Now.Minute & " s" & DateTime.Now.Second & "]"
        Try
            MkDir("C:\Inetpub\wwwroot\WriteMe\" & Session("ClearanceCode"))
        Catch
        End Try
        root = "C:\Inetpub\wwwroot\WriteMe\" & Session("ClearanceCode") & "\"
        strfilename = "C:\Inetpub\wwwroot\WriteMe\" & Session("ClearanceCode") & "\" & dateinfo & ".txt"

        check that a file has been uploaded 
        If Request.Files.Count <= 0 Then
        Else
            get the file data 
            file = Request.Files.Get(0)
            check thats its not too big 
            If file.ContentLength > 102400000 Then
            Else
                If file.ContentType <> "text/plain" Then
                Else
                    save file 
                    file.SaveAs(strfilename)
                End If
            End If
        End If
 
Last edited by a moderator:
I would change the IFs and add PostedFile to the Saveas
btw, do you really want to allow files of 100 Mb ?
Code:
If Request.Files.Count > 0 and  file.ContentLength < 102400000 and file.ContentType = "text/plain" Then
        file.PostedFile.SaveAs(strfilename)
end if
 
Last edited by a moderator:
I can answer your question:

Search for "machine.conig" on your HD (my file is under "C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\CONFIG\"

there is a line like this:

<httpRuntime executionTimeout="90" maxRequestLength="4096" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100"/>

Change the "maxRequestLength" to a number you need. Standart this are 4MB (4096Byte)

The Timeout is in minutes...

Regards,
Stefan
 
Back
Top