In windows application using VB, I need to open three xml files one after another from specific path. If first xml file is selected, file dialog pops for next xml.
I tried the below code but it is for selecting files together(ie, which works like shift + selecting files). But i dont want in this manner, i need to select files one after another. If first xml is selected, file dialog pops for selecting next file. LIKE THIS I NEED TO SELECT THREE FILES. Once it is done file dialog closes.
''''
Private Sub SystemDescriptionToolStripMenuItem_Click()
OpenFileDialog1.Filter = "All Files *.xml | *.xml"
OpenFileDialog1.MultiSelect = True
OpenFileDialog1.InitialDirectory = "D:\"
OpenFileDialog1.Title = "Select description files"
OpenFileDialog1.ShowDialog()
End Sub
''''
To use single select (the default) in the dialog box
Private Sub SystemDescriptionToolStripMenuItem_Click()
OpenFileDialog1.Filter = "All Files *.xml | *.xml"
OpenFileDialog1.InitialDirectory = "D:\"
OpenFileDialog1.Title = "Select description file"
For i = 1 To 3
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
ProcessXMLFile(OpenFileDialog1.FileName)
Else
MessageBox.Show($"Error on File #{i}. Try Again")
Exit Sub
End If
Next
End Sub
Private Sub ProcessXMLFile(path As String)
'Your code to process the file
End Sub
To use multi select, instruct the user to hold down the Ctrl key when clicking on a file in the dialog box.
Private Sub SystemDescriptionToolStripMenuItem_Click()
OpenFileDialog1.Filter = "All Files *.xml | *.xml"
OpenFileDialog1.Multiselect = True
OpenFileDialog1.InitialDirectory = "D:\"
OpenFileDialog1.Title = "Select description file"
Dim files(2) As String
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
files = OpenFileDialog1.FileNames
For Each file In files
ProcessXMLFile(file)
Next
Else
MessageBox.Show($"Error on selecting files")
End If
End Sub
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.