Hello Friends,

I have got confused with one topic

Scenario is such that....

I need to browse a file and copy the file from one location to another....

I am done with the file copying but I need to add the list of all files present under that folder in a control( dont know which control to use) and it shud be a link....so that when the user clicks that link it should open the file with that reader...

Suppose a pdf file shud be opened by the pdf reader...

Similarly I need to access
-> pdf
-> any image file
-> text file

Can anyone help me in this?

You can read out the file names into listbox but not sure windows app supports file location as hyperlink

You can read out the file names into listbox but not sure windows app supports file location as hyperlink

Yes I have done this now....

Try
            lstFiles.Items.Clear()
        Dim di As New IO.DirectoryInfo(Application.StartupPath & "\" + lblPattName.Text + lblPatientID.Text + "\")
        Debug.Print("di: " + di.ToString)
        Dim diar1 As IO.FileInfo() = di.GetFiles()
        Dim dra As IO.FileInfo
        'list the names of all files in the specified directory
        For Each dra In diar1
            lstFiles.Items.Add(dra)
        Next
        Catch ex As Exception
            MsgBox("Select Patient Name")
        End Try

but I dont know how to link these files.... :(

Process.Start("explorer.exe", Filepath)

Can you try something like this? filepath is the location of file which u have in listbox..

I am able to open all kinds of files using above code, Provided you have the file readers installed in machine..

I am able to open all kinds of files using above code, Provided you have the file readers installed in machine..

But how shud I link it with the filenames....

the filename in the list box are dynamic....

so I will I link it the the list box

and where shud the code be written

You are loading the full path of files into list box right? Then in selected index changed event of list box read the file path and load the file using Process.Start("explorer.exe", Filepath)

You are loading the full path of files into list box right? Then in selected index changed event of list box read the file path and load the file using Process.Start("explorer.exe", Filepath)

When the selected index gets changes it just opens the windows explorer every time....

and not the file...

Post your code here or try something like below

Private Sub ListBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedValueChanged
        If ListBox1.SelectedItem.ToString.Length > 0 Then
            Process.Start("explorer.exe", ListBox1.SelectedItem.ToString)
        End If
commented: Thank u very much +3

Post your code here or try something like below

Private Sub ListBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedValueChanged
        If ListBox1.SelectedItem.ToString.Length > 0 Then
            Process.Start("explorer.exe", ListBox1.SelectedItem.ToString)
        End If

Hey thanks Friend....got it solved

Try
            Dim path As String
            Dim abc As String = lstFiles.SelectedItem.ToString
            path = (Application.StartupPath & "\" + lblPattName.Text + lblPatientID.Text + "\" + abc).ToString
            Debug.Print("path in doc: " + path)
            Dim extension As String = IO.Path.GetExtension(path)
            Debug.Print("extension: " + extension)
            If extension = ".doc" Or extension = "docx" Then
                Process.Start("winword.exe", path)
            ElseIf extension = ".pdf" Then
                Process.Start("AcroRd32.exe", path)
            ElseIf extension = ".bmp" Or extension = ".jpeg" Or extension = ".jpg" Or extension = ".gif" Or extension = ".png" Or extension = ".ico" Then
                Process.Start("mspaint.exe", path)
            ElseIf extension = ".txt" Then
                Process.Start("notepad.exe", path)
            End If
        Catch ex As Exception
            MsgBox("Error")
        End Try

hello !
i know this thread is solved , but please also check this

Imports System.IO


   ' make a reference to a directory
    Dim di As New IO.DirectoryInfo("c:\")
    Dim diar1 As IO.FileInfo() = di.GetFiles()
    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

Regards

why some one down vote my post :-X with out any reason :-| , this is not fair :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.