ravula2000
IS-IT--Management
To upload a file, Iam using a file control and button control as follows.
<input id="ffileuploadedFile" type="file" size="50" runat="server" />
<input id="fbtnupload" type="button" value="Upload" runat="server" onserverclick="fbtnupload_Click" />
The Button click event is as follows..
Sub fbtnupload_Click(source As Object, e As EventArgs)
If Not (ffileUploadedFile.PostedFile Is Nothing) Then
Dim postedFile = fileUploadedFile.PostedFile
Dim filename As String = Path.GetFileName
(postedFile.FileName)
Dim lcSavepath As String = "C:\temp"
postedFile.SaveAs(lcSavepath & "\" &
filename)
End If
End Sub
The upload is working fine.
The problem is when no file is selected (textbox of file control is empty) and upload button is pressed it is still trying to upload and iam getting an error message. Basically the if condition "ffileUploadedFile.PostedFile Is Nothing" is returning false every time.
Is there a way to test wheter a file is selected for upload..
Thanks in advance.
Srini
<input id="ffileuploadedFile" type="file" size="50" runat="server" />
<input id="fbtnupload" type="button" value="Upload" runat="server" onserverclick="fbtnupload_Click" />
The Button click event is as follows..
Sub fbtnupload_Click(source As Object, e As EventArgs)
If Not (ffileUploadedFile.PostedFile Is Nothing) Then
Dim postedFile = fileUploadedFile.PostedFile
Dim filename As String = Path.GetFileName
(postedFile.FileName)
Dim lcSavepath As String = "C:\temp"
postedFile.SaveAs(lcSavepath & "\" &
filename)
End If
End Sub
The upload is working fine.
The problem is when no file is selected (textbox of file control is empty) and upload button is pressed it is still trying to upload and iam getting an error message. Basically the if condition "ffileUploadedFile.PostedFile Is Nothing" is returning false every time.
Is there a way to test wheter a file is selected for upload..
Thanks in advance.
Srini