ASP.NET 2.0 server control
FileUpload allows developers to drop the control on an ASP.NET page and upload the file to servers.
The following example shows how to use this control:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void btnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(@"C:\temp\" + FileUpload1.FileName);
Label1.Text = "File Uploaded: " + FileUpload1.FileName;
}
else
{
Label1.Text = "No File Uploaded.";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Upload a file to server</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload File" Width="105px" /><br />
<asp:Label ID="Label1" runat="Server"></asp:Label>
</div>
</form>
</body>
</html>
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
httpRuntime element configures ASP.NET HTTP run-time settings that determine how a request for an ASP.NET application is processed. The .NET Framework provides a number of different run-time hosts, including the ASP.NET run-time host.
When a request comes in, ASP.NET loads the run-time setting into the process that is to handle the request. ASP.NET also creates an application domain for each Web application that will run on a Web server.
The httpRuntime element is not explicitly defined in the Machine.config file or in the root Web.config file. However, the following settings are the default values as initialized by the system.
If you need to customize this section you must create it in your configuration file and define only those attributes that need customization.
<httpRuntime
executionTimeout="110"
maxRequestLength="4096"
requestLengthDiskThreshold="256"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="5000"
enableKernelOutputCache="true"
enableVersionHeader="true"
requireRootedSaveAsPath="true"
enable="true"
shutdownTimeout="90"
delayNotificationTimeout="5"
waitChangeNotification="0"
maxWaitChangeNotification="0"
requestPriority="Normal"
enableHeaderChecking="true"
sendCacheControlHeader="true"
apartmentThreading="false"
/>
The
maxRequestLength specifies the limit for the input stream buffering threshold, in KB. This limit can be used to prevent denial of service attacks that are caused, for example, by users posting large files to the server.
The following example demonstrates how to specify HTTP run-time parameters for an ASP.NET application.
<configuration>
<system.web>
<httpRuntime maxRequestLength="4000"
enable = "True"
requestLengthDiskThreshold="512
useFullyQualifiedRedirectUrl="True"
executionTimeout="45"
versionHeader="1.1.4128"/>
</system.web>
</configuration>