Validating file upload control
The File Upload class displays a text box control and a browse button that enable users to select a file on the client and upload it to the Web server.
The user specifies the file to upload by entering the full path of the file on the local computer (for example, C:\My Files\Test File.txt) in the text box of the control.
This example allows only files that have the or file name extensions to be uploaded. Get Extension method is called to return the extension of the file to upload.
If the file has a or file name extension, the Save As method is called to save the file to the specified path on the server.
The Content Type property gets the MIME content type of the file.
In addition, you can use the Posted File property to access the File Name property, the Input Stream property, and the Save As method.
Caution These examples demonstrate the basic syntax for the File Upload control, but they do not demonstrate all the necessary error checking that should be completed before to saving the file. The following example demonstrates how to create a File Upload control that saves files to a path that is specified in code.
The Save As method is called to save the file to the specified path on the server.