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!

Copy file selected in ListBox

Status
Not open for further replies.
Nov 19, 2002
5
US
I am very new at VB (3 days).

I have a form which has a dropdown box (comboDrives)that list the drives on the computer. Then a ListBox (lbFiles)that displays the files in the selected drive. I also have 2 radio buttons (rb8000, rb9000)for the user to select a folder to copy that file to. What I want to do is copy the file(s) they select to the folder they select.

I keep getting the error:
"An unhandled exception of type 'System.InvalidCastException' occurred in system.windows.forms.dll

Additional information: Cast from type 'FileInfo' to type 'String' is not valid."

My Code:
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

Dim x
x = lbFiles.SelectedItem

If rb8000.Checked = True Then
System.IO.File.Copy(x, "C:\Program Files\CheckPrint\Troy_8000\*.*")
Else
If rb9000.Checked = True Then
System.IO.File.Copy(x, "C:\Program Files\CheckPrint\HP_9000\*.*")
Else
MsgBox("You need to select a printer.", MsgBoxStyle.OKOnly)
End If
End If


End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top