Skip Navigation LinksASP.Net 2.0 Training : ASP.Net FileUpload
Banner for ASP.Net 2.0 training classes in Visual Basic 2005 

Skip Navigation Links
Visit my other site:

certification training

Free Flash tutorials and training

Free Dreamweaver Video Tutorials

Free PHP Training

Visual Basic Windows Training

If you like this site please link to it

FileUpload Control

The FileUpload Control allow you to upload files to the server
  • Open Visual Studio
  • Add a new webform
  • Name it fileUpload.aspx
  • Add a label control and name is message
  • Add a button control
  • Double click the button and add this code:

If Page.IsValid Then
FileUpload1.SaveAs( String.Concat( "C:\", FileUpload1.FileName))
message.Text = String.Concat( "The file '", FileUpload1.FileName, "' was successfully uploaded")
Catch ex As Exception
message.Text = String.Concat( "An error occurred uploading the file ", FileUpload1.FileName, "' – ", ex.Message)
End Try
End If

  • Add a customValidator Control
  • Double-click the validator control and add this code:

'Verify the control has a file
If Not FileUpload1.HasFile Then
CustomValidator1.ErrorMessage = "A file is required in order to proceed"
args.IsValid = False
Dim ext As String = System.Web.VirtualPathUtility.GetExtension(FileUpload1.FileName).ToUpper()
If Not ext = ".GIF" And Not ext = ".JPG" Then
CustomValidator1.ErrorMessage = String.Concat( "Invalid file type '", etx, "' - must be .gif or .jpg to continue")
args.IsValid = False
args.IsValid = True
End If
End If

  • Test it

      ASP.Net 2.0 tutorials & training