This is for an upload in asp.net to upload a file...
So I decided to still post in here.

How do I catch an error in case an upload doesnt take place...
Kinda new to asp.net with vb.net...
Can we still do on error goto a label...
Here is my code:

If there is something else I should do better please let me know.

VB Code:
  1. Dim strFileNameWithPath As String
  2.         Dim strFileName As String
  3.  
  4.         'This line will check whether a file is selected or not
  5.         If IsNothing(Me.MyFile.PostedFile) Then lbl.Text = "Select one file to upload" : Exit Sub
  6.         'This line will check whether the file selected is a zero length file
  7.         If MyFile.PostedFile.ContentLength = 0 Then
  8.             lbl.Text = "Cannot upload a zero length file!"
  9.             Exit Sub
  10.         Else
  11.             'Display the file name selected
  12.             'You can use this property with regular expression to check the file type
  13.             strFileNameWithPath = MyFile.PostedFile.FileName
  14.             strFileName = System.IO.Path.GetFileName(strFileNameWithPath)
  15.  
  16.             'Save the file to the directory
  17.             MyFile.PostedFile.SaveAs("\\jakah-iis-2\IMS\attachments\" & strFileName)
  18.             lbl.Text = strFileName & " uploaded successfully!"
  19.         End If

PS: The path is hardcoded right now but will change...how do I declare that path as a variable of this class (A constant) ... I just need it so that I can say:

Public Constant strPath as String = "\\jakah-iis2\IMS\attachments\"

Is that possible somewhere ?