简体   繁体   中英

How to open multiple documents using vb.net file explorer?

I made a file explorer using vb.net the way I wanted it but the problem is that I have several test folders and every day I will put several pdf files and images inside those folders and when I enter the folder test1 I have the pdf file newtest and I have other files and when I go to click on a file it opens this file only if I put the path of the pdf file newtest preset and when I click on another it opens the other file if I put preset but I go have over a thousand image files and more than a thousand pdf files in these folders and I want to know what the code would be for when I click on a file it opens and when I click on another file the other file opens. I can only do this with each pre-selected file and this is not feasible.

As the code shows:

Else

Process.Start ("C: \\ Test \\ test1 \\ newtest.pdf") End If

I want it to open multiple files when I click each one of them one by one without having to be writing this code for each image and pdf file name separately.

Help me with this, please?

Image with file explorer design

Public Class Form1
Dim path As String
Dim nextPath As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    On Error Resume Next
    path = TextBox1.Text
    If (My.Computer.FileSystem.DirectoryExists(path)) Then

        explorer.Clear()

        For Each i In My.Computer.FileSystem.GetDirectories(path)
            explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2)

        Next
        For Each i In My.Computer.FileSystem.GetFiles(path)
            explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1)
        Next
    Else
        MsgBox("Its A File")
        'or user
        'pocess.Start(path) // to open the file
    End If

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    On Error Resume Next
    path = "C:\Test"
    For Each i In My.Computer.FileSystem.GetDirectories(path)
        explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2)

    Next
    For Each i In My.Computer.FileSystem.GetFiles(path)
        explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1)
    Next

End Sub

Private Sub ListView1_ItemSelectionChanged(sender As Object, e As ListViewItemSelectionChangedEventArgs) Handles explorer.ItemSelectionChanged
    nextPath = path + "\" + e.Item.Text

End Sub

Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles explorer.SelectedIndexChanged


End Sub

Private Sub ListView1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles explorer.MouseDoubleClick
    On Error Resume Next
    If (My.Computer.FileSystem.DirectoryExists(nextPath)) Then
        path = nextPath
        explorer.Clear()
        TextBox1.Text = path
        For Each i In My.Computer.FileSystem.GetDirectories(path)
            explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 2)

        Next
        For Each i In My.Computer.FileSystem.GetFiles(path)
            explorer.Items.Add(i.Substring(i.LastIndexOf("\") + 1), ImageList1.Images.Count() - 1)
        Next
    Else

        Process.Start("C:\Test\test1\newtest.pdf")
    End If

End Sub


Private Sub BtnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click

End Sub

Private Sub BtnForward_Click(sender As Object, e As EventArgs) Handles btnForward.Click

End Sub

End Class

if you still want to go with clicking on listview items to open it try this:

process.start(path & ListView1.SelectedItems(0).Text)

this will open C:\\test\\test1\\newtest.pdf (for example)

Update:

look, it worked for me, double clicking "internet tester.exe" opens it. if your "path" does not contain "\\" at the end make sure to add it yourself. mark the answer as answer if it works for you too

在此输入图像描述 在此输入图像描述 在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM