O'Reilly logo

Programming ASP.NET, 3rd Edition by Dan Hurwitz, Jesse Liberty

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

FileUpload Control

Often an application finds the need to allow users to upload files to the web server. Although it was possible to do this in ASP.NET Version 1.x, it is made much easier in ASP.NET Version 2 with the introduction of the FileUpload control.

This control makes it easy for the user to browse for and select the file to transfer, providing a Browse button and a text box for entering the file name. Once the user has entered a fully-qualified file name in the text box, either by typing it directly or using the Browse button, the SaveAs method of the FileUpload control can be called to save the file to disk.

In addition to the normal complement of members inherited from the WebControl class, the FileUpload control also exposes several read-only properties of particular interest, listed in Tables 5-8 and 5-9.

Table 5-8. FileUpload properties

Name

Type

Get

Set

Description

FileContent

Stream

 

Returns a Stream object that points to the file to upload.

FileName

string

 

Returns the name of the file to be uploaded, without any qualifying path information.

HasFile

Boolean

 

If true, indicates that the control has a file to upload.

PostedFile

HttpPostedFile

 

Returns a reference to the file which has been uploaded. Exposes the read-only properties listed in Table 5-9.

Table 5-8. HttpPostedFile properties

Name

Type

Get

Set

Description

ContentLength

integer

 

Returns the size of the file, in bytes, of an uploaded 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