O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Upload a File

Problem

You need to create a page that allows the user to upload a file.

Solution

Use the ASP.NET HtmlFileInput control.

Discussion

Because ASP.NET executes on the server, there is no way to access any of the resources on the client computer, including files. However, you can use the HtmlFileInput control to allow a user to upload a file. This control renders itself as the HTML <input type="file"> element, which is displayed as a Browse button and a text box that contains a filename. The user clicks the Browse button and chooses a file. This step takes place automatically and requires no custom code. The user must then click another button (which you must create) to start the actual upload process.

Before you can create a working file ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required