FileUpload control in Asp.Net  

The FileUpload control allows the user to upload a file from local machine to the web server. By default maximum size of a file to be uploaded to the server using FileUpload control is 4096KB(4MB) and it can be changed.

0 777 Technology | Asp.Net
Tue Dec 25 , 2018

The FileUpload control displays a textbox and a browse button in which user can either entering the filename in the text box by typing the name or can select a file and its path by browsing.

The FileUpload control allows users to upload images, text files, or other files around 4096KB(4MB) because by default the maximum size of a file to be uploaded to the server using the FileUpload control is 4MB.

If users attempt to upload a file larger than the 4 megabyte (MB) , then the upload fails. To overcome this, you have to change the default file size in web.config.comments file found at C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config.comments or your application's web.config file(i.e. if you want to apply this to your particular application, overriding any setting that is in the web.config.comments file to <system.web>) for maxRequestLength of httpRuntime tag.

If you allows users to upload 10 megabyte (MB) files to the server, set the maxRequestLength value to 11264 kilobyte.

executionTimeout = "110" [in Seconds]
maxRequestLength = "4096" [in KB]            [By Default]
requestLengthDiskThreshold = "80"
useFullyQualifiedRedirectUrl = "false"
minFreeThreads = "8" [number]
minLocalRequestFreeThreads = "4"
appRequestQueueLimit = "5000"
enableKernelOutputCache = "true"
enableVersionHeader = "true"
apartmentThreading = "false"
requireRootedSaveAsPath = "true"
enable = "true" [true|false]
sendCacheControlHeader = "true"
shutdownTimeout = "90" [in Seconds]
delayNotificationTimeout = "5" [in Seconds]
waitChangeNotification = "0"
maxWaitChangeNotification = "0"
enableHeaderChecking = "true"
sendCacheControlHeader="true" />

Syntax of FileUpload control

<asp:FileUpload ID= "FilUplod" runat = "server" />

Example of FileUpload control


<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
    <div style="text-align:center;margin-top:10%;">
    <asp:FileUpload ID="FilUplod" runat="server"/>
    <asp:Label ID="lblMsg" runat="server"></asp:Label>
    <asp:Button ID="btnUpload" runat="server" onclick="btnUpload_Click" Text="Upload" />


protected void btnUpload_Click(object sender, EventArgs e)
	if (FilUplod.HasFile)
		//create fileupload folder in root directory
                FilUplod.SaveAs(Server.MapPath("~/fileupload/" + FilUplod.FileName));
                lblMsg.Text = "File Uploaded";
                lblMsg.ForeColor = System.Drawing.Color.ForestGreen;
          	lblMsg.Text = "Please select file";
                lblMsg.ForeColor = System.Drawing.Color.Red;

Subscribe & Get Regular Updates On Your E-mail