HtmlInputFile class properties and its descriptions

This ASP.NET reference explains HtmlInputFile class properties and its descriptions.

Web developers can use this class to programmatically access the HTML <input type= file> element on the server and to use the control to handle uploading binary or text files from a browser client to the server. The HtmlInputFile control is designed to be used only in postback scenarios and not in asynchronous postback scenarios during partial-page rendering. When Web developers use a HtmlInputFile control inside an UpdatePanel control, the file must be uploaded by using a control that is a PostBackTrigger object for the panel. UpdatePanel controls are used to update selected regions of a page instead of updating the whole page with a postback.

Web developers can determine the file to upload, by entering the full path to the file (for example, “C:\My Documents\MyTestFile.txt”) in the text box of the control. They can also select the file by clicking the Browse button and then locating it in the Choose file dialog box. Note: The Enctype property of an HtmlForm control must be set to “multipart/form-data” for this control to work properly.

The HtmlInputFile control does not have a built-in way to post back to the server and Web developers should use the SaveAs method of the System.Web.HttpPostedFile object contained in the PostedFile property to upload the file to the server. This operation is usually done in an event-handling method, such as for a button click. Note: When Web developers use the SaveAs method of the HttpPostedFile class, they should specify a rooted path (for example, ” C:\My Documents\MyTestFile.txt”). The behavior of the SaveAs 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 they set this attribute to false, then using the SaveAs 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 cannot be saved there. Web site administrators/Web developers should provide write permission for the account used by ASP.NET for the directory where they want to store the file.

When end user is going to upload large files, Web developers should use the maxRequestLength attribute of the httpRuntime Element (ASP.NET Settings Schema) element to increase the maximum allowable file size. A DNS error is generated in the browser when the file exceeds the specified size. End users 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).

In this case Web site administrators should, increase the value of the memoryLimit attribute in the processModel Element (ASP.NET Settings Schema) element of the Machine.config file.

Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in System.Web.dll)

Property

Description

Supported in .NET version

Accept

This string property is used to get or set a comma-separated list of MIME encodings used to constrain the file types the user can select. Note: Support for this property is browser-dependent. Web developer should check his/her browser to specify whether it supports this property. It is recommended that Web developer uses server-side code to ensure that the file is of the expected type.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

Adapter

This property gets the browser-specific adapter for the control. If the target browser does not require an adapter, returns a null reference (Nothing in VB.NET). The property returns the ControlAdapter object that renders the control on the requesting device or browser’s screen.

2.0, 3.0, 3.5, 4.0

AppRelativeTemplateSourceDirectory

 

Software developer can use this property to set or get the application-relative path to the page or user control that contains the current control.  If the web page is installed in http://www.somesite.com/apps/application1 the property will return “~/application1”.

2.0, 3.0, 3.5, 4.0

Attributes

Web developer can use this property to get a collection of all attribute name and value pairs expressed on a server control tag within the ASP.NET page. Using this property Web developer accesses the attributes of the HTML server control which are stored in Control.ViewState property. HTML attributes are treated by the .NET Framework as properties on the HTML server control to which they belong.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

BindingContainer

Software developer can’t use this property directly from his/her code, because it supports the .NET Framework infrastructure.  The property contains a reference to the Control object which contains data-binding information for the current control.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

ChildControlsCreated

Gets a true value that indicates whether the server control’s child controls have been created.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

ClientID

Returns the server control identifier generated by ASP.NET. The ClientID value is generated by concatenating the ID value of the control and the UniqueID value of its parent control. If the ID value of the control is not specified, an automatically generated value is used. Each part of the generated ID is separated by an underscore character (_).

1.0,1.1, 2.0, 3.0, 3.5, 4.0

ClientIDSeparator

The ClientID value is generated by concatenating the ID value of the control and the UniqueID value of its parent control. Each part of the generated ID property is separated by the ClientIDSeparator property value. The value always returns an underscore (_).

1.0,1.1, 2.0, 3.0, 3.5, 4.0

Context

Software developer can use this property to access the HttpContext object for the current Web request. Using properties of the object software developer can access objects Application, Session, Request, Response, etc. which contain information about the current HTTP request. The object provides methods that allow him to get configuration information and to set or clear errors related to the request.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

Controls

This property allows software developer to access programmatically to the instance of the ControlCollection class for any server control. Using it he/she can add/remove controls to/from the collection or iterate through the server controls in the collection.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

DesignMode

This property returns true to indicate that the control is being used in the context of a designer. Software developer’s custom controls can use this property when design-time behavior is different than run-time behavior.

2.0, 3.0, 3.5, 4.0

Disabled

This property is used to get or set a value indicating whether the HTML server control is disabled. Its default value is false i.e. the control is enabled. In the browser, a disabled element or control is read-only, with the following added restrictions:

- its value is not submitted with the form,

- the element or control cannot receive focus

- the element or control is skipped when navigating the document by tabbing.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

EnableTheming

This property overrides Control. EnableTheming.

The property indicates whether themes are enabled for a specified control. When the property’s value is true, the application’s theme directory is searched for control skins to apply. If for the particular control skin does not exist in the directory, skins are not applied. When the property’s value is false, the theme directory is not searched and the contents of the SkinID property are not used.

2.0, 3.0, 3.5, 4.0

EnableViewState

Software developer must enable view state for the server control setting its value to true if he/she wants to maintain its state across HTTP requests. Sometimes is better to set value of this property to false if for example Web application is loading a database request into a server control. In this case application performance will be improved.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

Events

This read-only property returns a list of event handler delegates for the control. The type of this property is EventHadlerList, which uses a linear search algorithm to find entries in the list of delegates. When the list of delegates is large, finding entries with this property will be slow, because a linear search algorithm is inefficient when working with a large number of entries.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

HasChildViewState

Software developer can use this property to verify that any child controls of the server control are storing view-state information. Using it in this way he/she can avoid unnecessary calls to the ClearChildViewState method.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

ID

Web developers can set this property by declaring ID attribute in the opening tag of an ASP.NET server control. Another possible way to set it is programmatically. If this property is not specified for a server control, either declaratively or programmatically, Web developer can obtain a reference to the control through its parent control’s Controls property.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

IdSeparator

Software developer can’t use this property directly from his/her code, because it supports the .NET Framework infrastructure.   The character contained in this property ( by default $ ) is used to separate the control identifiers for child controls. The ID separator character is appended to the ID property.

2.0, 3.0, 3.5, 4.0

IsChildControlStateCleared

This property has value true if children of this control do not use control state; otherwise, false.

2.0, 3.0, 3.5, 4.0

IsTrackingViewState

This property returns value true if the control is marked to save changes to its view state; otherwise, false.

 

1.0,1.1, 2.0, 3.0, 3.5, 4.0

IsViewStateEnabled

This property returns value true if view state is enabled for the control; otherwise false.  View state can be enabled at the page, container, or control level. When view state is disabled at the page or container level, view state is disabled for all controls contained by the page or container. The property indicates whether view state is enabled by pages, containers, or controls. In some cases it is possible values for the EnableViewState property and the IsViewStateEnabled property to be different. For example, if the Page containing the control has view state disabled, the EnableViewState property can be true while the IsViewStateEnabled property is false. Notes: Developers will set the EnableViewState property to indicate whether they are using view state with your control. Web developers can use this property in their code to determine whether view state is enabled for their control and all containers.

2.0, 3.0, 3.5, 4.0

LoadViewStateByID

This property returns value true if the control loads its view state by ID; otherwise, false. Its default value is false.

2.0, 3.0, 3.5, 4.0

Name

This string property is inherited from HtmlInputControl and is used to get or set the unique identifier name for the HtmlInputControl control. Note: The property’s set accessor does not assign a value to it because the Name property must have the same value as the Control.UniqueID property for most controls to work properly.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

NamingContainer

Using this property software developer can get a reference to the server control’s naming container, which creates a unique namespace for differentiating between server controls with the same Control.ID property value.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

Page

Provides a reference to the web page that contains this control as a System.Web.UI.Page object.  This property’s value reflects the name of the .aspx file that contains the server control.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

Parent

This property provides a reference to the control that contains this control. If the control is placed on the page directly (rather than inside another control), it will return a reference to the page object.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

PostedFile

This property returns access to the uploaded file specified by a client. Browser security restrictions prevent this value from being maintained across multiple requests.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

Site

Using this property software developer can get information about the container that hosts the current control when rendered on a design surface.  A site binds a Component object to a Container object and enables communication between the two. It also provides a way for the container to manage its components.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

Size

This property is used to get or set the width of the text box in which the file path is entered. Its default value is -1, which indicates that the property has not been set.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

SkinID

This property overrides Control.SkinID.

Web developer can get or set the skin to apply to the control.  Skins available to a control are contained in one or more skin files in a theme directory. The SkinID property specifies which of these skins to apply to the control. A skin is specific to a particular control i.e. software developer cannot share skin setting between controls of different types. If developer does not set the SkinID property, a control uses the default skin if one is defined.

2.0, 3.0, 3.5, 4.0

Style

Web developer can use this property to get a collection of text attributes that will be rendered as a style attribute on the outer tag of the Web server control. This property will render on all browsers for all controls.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

TagName

Web developers can use this property to get the name of the control tag. This property is used primarily by control developers.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

TemplateControl

This property is used to get or set a reference to the template that contains this control.

2.0, 3.0, 3.5, 4.0

TemplateSourceDirectory

Software developer can use this property to get the path to the page or user control that contains the current control.  If the web page is installed in http://www.somesite.com/apps/application1 the property will return “apps/application1”.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

Type

This property is inherited from HtmlInputControl  and returns the type of an HtmlInputControl. The following list shows the different possible values for the Type property:

-          text – A text box for data entry.

-          password – A text box that masks user input.

-          checkbox – A check box that indicates a true or false condition.

-          radio – A radio button that indicates a selection from a mutually exclusive group of radio buttons.

-          button – A command button.

-          submit – A button that submits the form to the server.

-          reset – A button that clears the form.

-          file – A button that uploads a file.

-          hidden – A non-visible field on a Web page used to persist information between posts to the server.

-          Image – An image button.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

UniqueID

This property can be used to get the unique, hierarchically qualified identifier for the server control. This property differs from the ID property, in that the UniqueID property includes the identifier for the server control’s naming container. This identifier is generated automatically when a page request is processed. This property is particularly important in differentiating server controls contained within a data-binding server control that repeats as Repeater, DataList, DetailsView, FormView, and GridView Web server controls.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

Value

This string property returns the full path of the file on the client’s computer. This property is also commonly used to determine the original file name. Web developer can get the original file name, by parsing the value of this property.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

ViewState

Web developers can use this property to get a dictionary of state information that allows them to save and restore the view state of a server control across multiple requests for the same page.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

ViewStateIgnoresCase

This property returns true if StateBag object is insensitive; otherwise, false. Its default value is false.

1.0,1.1, 2.0, 3.0, 3.5, 4.0

Visible

Web developers can use this property to get or set a value that indicates whether a server control is rendered as UI on the page. If the control is visible on the page this property will has value true; otherwise false.

1.0,1.1, 2.0, 3.0, 3.5, 4.0