Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File upload problem

Status
Not open for further replies.

ravula2000

IS-IT--Management
Mar 8, 2002
205
US
To upload a file, Iam using a file control and button control as follows.

<input id=&quot;ffileuploadedFile&quot; type=&quot;file&quot; size=&quot;50&quot; runat=&quot;server&quot; />
<input id=&quot;fbtnupload&quot; type=&quot;button&quot; value=&quot;Upload&quot; runat=&quot;server&quot; onserverclick=&quot;fbtnupload_Click&quot; />

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 = &quot;C:\temp&quot;
postedFile.SaveAs(lcSavepath & &quot;\&quot; &
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 &quot;ffileUploadedFile.PostedFile Is Nothing&quot; is returning false every time.
Is there a way to test wheter a file is selected for upload..

Thanks in advance.

Srini
 
if(ffileUploadedFile.PostedFile.FileName.Length) > 0

...should do the trick...

-----------------------------------------------
&quot;The night sky over the planet Krikkit is the least interesting sight in the entire universe.&quot;
-Hitch Hiker's Guide To The Galaxy
 
Thanks man...
The trick is working fine..
Thanks a lot.
Srini
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top