FileUpload Object
In the HTML document <input type= "file" > tag each time a FileUpload object is created.
This element contains a text input field that is used to enter the file name and a button to open the File Selection dialog box for a graphical selection of files.
The Value property of the element holds the name of the file specified by the user, but when a form containing a FILE-UPLOAD element is submitted, the browser sends the contents of the selected file to the server, not just the file name.
For security reasons, the File-upload element does not allow the HTML author or JavaScript programmer to specify a default file name. The HTML Value property is ignored, and the Value property is read-only for such elements, which means that only the user can enter a file name. When the user selects or edits a file name, the file-upload element triggers the onchange event handle.
You can access the FileUpload object by traversing the elements[] array of the form, or by using document.getElementById ().
FileUpload properties of an object
| Properties |
Description |
| Accept |
Sets or returns a comma-delimited list of MIME types that indicate file transfers. |
| AccessKey |
Sets or returns the shortcut key that accesses the FileUpload object. |
| Alt |
Sets or returns the alternate text that is displayed when <input type= ' file ' > is not supported. |
| DefaultValue |
Sets or returns the initial value of the FileUpload object. |
| Disabled |
Sets or returns whether the FileUpload object is disabled. |
| Form |
Returns a reference to the form that contains the FileUpload object. |
| Id |
Sets or returns the ID of the FileUpload object. |
| Name |
Sets or returns the name of the FileUpload object. |
| TabIndex |
Sets or returns the index number that defines the tab control order of the FileUpload object. |
| Type |
Returns the type of the form element. For FileUpload, it is "file". |
| Value |
Returns the file name of the FileUpload object after the text set by the user input. |
Standard properties
| Properties |
Description |
| ClassName |
Sets or returns the Class property of an element. |
| Dir |
Sets or returns the direction of the text. |
| Lang |
Sets or returns the language code of the element. |
| Title |
Sets or returns the title property of an element. |
Methods for FileUpload objects
| Method |
Description |
| Blur () |
Moves the focus away from the FileUpload object. |
| Focus () |
Gives focus to the FileUpload object. |
| Select () |
Select the FileUpload object. |
MVC Fileupload-form
* There are several ways to upload files, including form form submission method, the following is the procedure
1. Settings <form> Form Properties
Action = "Submit Address"; Default "/" (current controller) in MVC
Method = "Submission method"; Post must be selected
2. Save the file
Use system.web.httpcontext.current.requst.files[]; receive files with a file type of Httppostefile
Document upload details (HTML file)