Cast from type 'FileInfo' to type 'String' is not valid. *[resolved]*
Code:
' make a reference to a directory
Dim di As New IO.DirectoryInfo("c:\program files\jp\news\data\")
Dim diar1 As IO.FileInfo() = di.GetFiles("*.newspaper")
Dim dra As IO.FileInfo
'list the names of all files in the specified directory
For Each dra In diar1
ListBox1.Items.Add(dra)
Next
Code:
Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
Dim filename As String = ListBox1.SelectedItem ' this dos not work
End Sub
When I dubble click listbox1 then I get this error:
***************************************************
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from type 'FileInfo' to type 'String' is not valid.
***************************************************
I need to be able to add the selected text into a FileOpen command:
Ok I attched the program. Not much is working on it becuase I got stuck on the problem early.
Look at the readme.txt file.
Look at the Create.bmp file
Thanks for helping!
Edit: You might want to change the paths of the FileOpen and filesearch because it is set to "C:/program files/jp/news/data"
or you could just create that directory(the program won't do it for you)
I had to change all your hard coded paths of "C:/program files/jp/news/data/" to Application.StartupPath....which is something I suggest you go ahead and use yourself that way nothing is hard coded.
I marked the two areas that I fixed with what I believe to be the problem. No more errors when I run the app.
'I have it setup so that the name of the file is the persons name, the first line is the persons address then followed by a comma, then I have the collection method