Upload files in ASP.NET

Assalamualaykum Wr Br…Today we make tour of the ASP.NET FileUpload Control. Asp.Net FileUpload Control allows users to upload files on the web server. It automatically sets the encoding of the form. It allows the users to browser for and select the file to be uploaded, providing the Browse Button and TextBox for entering the File Name. Once the User has entered the File Name in the TextBox by typing the Name or Browsing, the SaveAs method of the FileUpload Control can be called to save the file to the disk.

The basic syntax of the FileUpload Control is:

The FileUpload Class is derived from WebControl Class, and inherits all its members. There are some read only properties which can be stated as:
1. FileName.
2. HasFile.
3. FileBytes.
4. FileContent.
5. PostedFile.

The posted File is encapsulated in an object of type HttpPostFile, which could be accessed through the PostedFile Property of the FileUpload Class.

The HttpPostedFile has Following properties:
1. ContentLength
2. ContentType
3. FileName
4. InputStream
Now, Let us start the Practice Session…Design the ASP.NET page as shown below:

The Above Design view can be coded as shown below:

The Code Behind for the button SAVE is shown as:
When this Program is executed we get the following output:

Hope enjoyed this tour…Jazakallah khair

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s