How to upload large file to server using FileUpload control

FileUpload control in ASP.NET is used to upload the file to the server. If we want to upload the large file which is having more than 4096 KB, then we have to change the HttpRunTime Parameter maxRequestLength.

FileUpload control in ASP.NET is used to upload the file to the server.
The following code shows how to use the FileUpload control:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">
protected void btnFileUpload_Click(object sender, EventArgs e)
if (FileUpload1.HasFile)

FileUpload1.SaveAs(@"D:\temp\" + FileUpload1.FileName);
lblMessage.Text = "File Uploaded: " + FileUpload1.FileName;
lblMessage.Text = "No File Uploaded.";

<html xmlns="" >
<head runat="server">
<title>Upload a file to server</title>
<form id="form1" runat="server">
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<asp:Button ID="btnFileUpload" runat="server" OnClick="btnFileUpload_Click" Text="Upload File" Width="105px" /><br />

<asp:Label ID="lblMessage" runat="Server"></asp:Label>


By default, the maximum file size that can be uploaded to the server is 4096KB. To upload larger files, you need to make change either in the Machine.config or Web.config for httpRuntime element. The maxRequestLength specifies the limit for the file to be uploaded, in KB.

The following code shows how to specify HTTP run-time parameters for an ASP.NET application.

<httpRuntime maxRequestLength="4096"
enable = "True"


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: