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
ASP.Net 2.0 Training
VS File Management
ASP.Net Image
ASP.Net Checkbox
ASP.Net ImageButton
ASP.Net RadioButton
ASP.Net Literal
ASP.Net Panel
ASP.Net LinkButton
ASP.Net Calendar
ASP.Net BulletedList
ASP.Net FileUpload
ASP.Net User Controls
ASP.Net PlaceHolder
ASP.Net Lists
ASP.Net CheckBoxList
ASP.Net DropDownList
ASP.Net Data Access
ASP.Net DetailsView
ASP.Net FormView
ASP.Net Repeater Control
ASP.Net:Master Pages
Sending EMail
MultiView
Tabbed MultiView
ASP.Net:Wizard Control
Login Controls 1
ASP.Net:Site Navigation
ASP.Net:Classes
ASP.Net:SQLDataSource Control
ASP.Net:Error Handling
ASP.Net:dataTables
ASP.Net:datasets

Visit my other site:

Free Flash 8 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
Try
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
Else
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
Else
args.IsValid = True
End If
End If

  • Test it


      ASP.Net 2.0 tutorials & training