Increase File Upload Size Limit in Asp.net

Steps:

1) Create the simple web application.

2) On the Form put the below control.

2.1) File Upload Control (id: FileUpload1)

2.2) button control (id: btnUpLoad)

2.3) label control (id: lblError)

3) On the click event of the button (btnUpload) write following code.

‘check whether user selected any file or not

If FileUpload1.HasFile Then

Try

where you want to save this file –here is your drive information

FileUpload1.SaveAs(“C:\TestUpload\” & FileUpload1.FileName)

lblError.Text = “File Upload Successfully”

Catch ex As Exception

‘if any error occured at that time display message to user

lblError.Text = “ERROR: “ & ex.Message.ToString()

End Try

Else

‘if user is not selected any file at that time

lblError.Text = “Please Select The File”

End If

3) on above coding you upload file up to around 4 MB.

4) now change the setting in the web config file which are below.

4.1) <httpRuntime maxRequestLength=10000/>

By default maxRequestLength is 4096 kb. You can change that here.

Thanks.

One response to “Increase File Upload Size Limit in Asp.net”

  1. Hi, I have fixed my maxRequestLength as 51200 (50MB). while uploading more than 25MB will not work. “file or directory not found” error will occur. How to fix this issue?

Leave a Reply

Discover more from AI Infrastructure Architect & Enterprise Solution Architect

Subscribe now to keep reading and get access to the full archive.

Continue reading