System.Web.UI.HtmlControls.HtmlInputFile Class

Allows programmatic access to the HTML <input type= file> element on the server.

See Also: HtmlInputFile Members

Syntax

[System.Web.UI.ValidationProperty("Value")]
public class HtmlInputFile : HtmlInputControl, System.Web.UI.IPostBackDataHandler

Remarks

Use the System.Web.UI.HtmlControls.HtmlInputFile server control to handle uploading binary or text files from a browser client to the server. File upload works with Microsoft Internet Explorer version 3.02 or later.

Note:

The System.Web.UI.HtmlControls.HtmlInputFile control is designed to be used only in postback scenarios and not in asynchronous postback scenarios during partial-page rendering. When you use a System.Web.UI.HtmlControls.HtmlInputFile control inside an System.Web.UI.UpdatePanel control, the file must be uploaded by using a control that is a System.Web.UI.PostBackTrigger object for the panel. System.Web.UI.UpdatePanel controls are used to update selected regions of a page instead of updating the whole page with a postback. For more information, see UpdatePanel Control Overview and Partial-Page Rendering Overview.

To specify the file to upload, enter the full path to the file (for example, "C:\MyFiles\Test.txt") in the text box of the control. You can also select the file by clicking the Browse button and then locating it in the Choose file dialog box.

Note:

The HtmlForm.Enctype property of an System.Web.UI.HtmlControls.HtmlForm control must be set to "multipart/form-data" for this control to work properly.

The System.Web.UI.HtmlControls.HtmlInputFile control does not have a built-in way to post back to the server. To upload the file to the server, use the System.Web.HttpPostedFile.SaveAs(string) method of the System.Web.HttpPostedFile object contained in the HtmlInputFile.PostedFile property. This operation is usually done in an event-handling method, such as for a button click.

Note:

When you use the System.Web.HttpPostedFile.SaveAs(string) method of the System.Web.HttpPostedFile class, make sure to specify a rooted path (for example, "C:\MyFiles\Test.txt"). The behavior of the System.Web.HttpPostedFile.SaveAs(string) method can be specified in the httpRuntime Element (ASP.NET Settings Schema) configuration section with the requireRootedSaveAsPath attribute. The default value of this attribute is true. If you set this attribute to false, then using the System.Web.HttpPostedFile.SaveAs(string) method with no path specified will attempt to place the file in the systemroot \system32\inetsrv directory. By default, this directory is write-protected; therefore, the file can not be saved there. Make sure to provide write permission for the account used by ASP.NET for the directory where you want to store the file.

When uploading large files, use the maxRequestLength attribute of the <httpRuntime> element to increase the maximum allowable file size. A DNS error is generated in the browser when the file exceeds the specified size. You might also receive the following error message when uploading large files:

aspnet_wp.exe (PID: 1520) was recycled because memory consumption exceeded 460 MB (60 percent of available RAM).

If you encounter this error message, increase the value of the memoryLimit attribute in the <processModel> element of the Machine.config file.

For a list of initial property values for an instance of System.Web.UI.HtmlControls.HtmlInputFile, see the HtmlInputFile.#ctor constructor.

Requirements

Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0