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:
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
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 ?




Reply With Quote