In this article I will explain with an example, how to use FileUpload control to accept Excel files in ASP.Net.
HTML Markup
The following HTML Markup consists of:
FileUpload – For uploading file.
The FileUpload control has been set with the following attribute.
accept - This attribute allows user to select only specified type of files from the Choose File dialog box.
Note: Please note accepting all files is default behavior and hence even if the accept attribute is not specified, by default, it will accept all files.
For example, in the following code, the FileUpload control will only allow user to select Excel file i.e. file with extensions xls, xlsx.
<asp:FileUpload runat="server" accept=".xls, .xlsx" />
Screenshot
Browser Compatibility
The above code has been tested in the following browsers only in versions that support HTML5.
* All browser logos displayed above are property of their respective owners.
Demo
Downloads