Uploading Files Using HtmlInputFile

ASP.NET provides an easy way to enable users to upload files to a server using the HtmlInputFile class. The HtmlInputFile class enables you to have programmatic access to the INPUT control of the FILE type. For those of you not familiar with what the File INPUT control is, see the following example:

<input type="file" id="UploadFile">

When this control is inserted into your page, you'll receive the following when the page is rendered: a textbox with a button directly to the right of it with the text Browse on it.

Notice in Figure 13.1 that a Browse button is rendered along with a textbox. This enables the user to browse his local hard drive for a file to upload. Users using older browsers might not receive ...

Get Programming Data-Driven Web Applications with ASP.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.