Working with FileUpload Control

This will show you how to access FileUpload properties programmatically and how to save a file selected by FileUpload control.

Hi All,

FileUpload control is used to allow user to select and upload single file at desired location. This control contains textbox and Browse button.
This control can be represented as as a source element. This element is singleton as no content is specified between opening and closing tag of this control.

Lets take a example. Suppose you have web page and fileupload control is added to it. In addition add a button control to submit the file to web server via postback.

Protected Button1_Click(ByVal sender as Object, Byval e as System.EventArgs) handles Button1.Click

If (FileUpload1.hasfile) then
'Suppose you have lable control to display information of selected file
Label1.Text = "File Length: " + FileUpload1.FileBytes.Length.ToString() _
+ "
" + "File Name:" + FileUpload1.FileName _
+ "MIME Type" + FileUpload1.PostedFile.ContentType

FileUpload1.SaveAs (MapPath([Path] + FileUpload1.FileName))
Label1.Text = "No File Received."
End if
End Sub

Hope this is of help.


Related Articles

Upload and Compressed file

By using the code you can upload file and then compressed it. It Retrieve file information and upload to server.

More articles: FileUpload FileUpload dialog


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: