Results 1 to 8 of 8

Thread: Cast from type 'FileInfo' to type 'String' is not valid. *[resolved]*

Threaded View

  1. #1

    Thread Starter
    Addicted Member ProgrammerJon's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    203

    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:



    Code:
    FileOpen(1, "C:/program files/jp/news/data/" & filename, OpenMode.Input)
    I there another way I can do this?
    Last edited by ProgrammerJon; Feb 9th, 2003 at 11:43 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width