Dim strFileNameWithPath As String
Dim strFileName As String
'This line will check whether a file is selected or not
If IsNothing(Me.MyFile.PostedFile) Then lbl.Text = "Select one file to upload" : Exit Sub
'This line will check whether the file selected is a zero length file
If MyFile.PostedFile.ContentLength = 0 Then
lbl.Text = "Cannot upload a zero length file!"
Exit Sub
Else
'Display the file name selected
'You can use this property with regular expression to check the file type
strFileNameWithPath = MyFile.PostedFile.FileName
strFileName = System.IO.Path.GetFileName(strFileNameWithPath)
'Save the file to the directory
MyFile.PostedFile.SaveAs("\\jakah-iis-2\IMS\attachments\" & strFileName)
lbl.Text = strFileName & " uploaded successfully!"
End If