displaying the content(files) of a directory with a button click
hi , i have a directory say "c:\root\sample" and i have some files inside this directory and i want to see the content of the directory with clicking a button in the program. how to do that many thanks
Hello. Depending on your version of Visual Studio and how far you want to go you might want to add a listbox and in the button's click event do something like the following
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ShowDirectoryContents("c:\root\sample")
End Sub
Private Sub ShowDirectoryContents(ByVal path As String)
For Each foundFile As IO.FileInfo In New IO.DirectoryInfo(path).GetFiles
Me.ListBox1.Items.Add(foundFile.FullName)
Next
End Sub
A slightly more advanced approach might fill up a treeview with the full path hierarchy of your drives and in the AfterSelect event make a call to the ShowDirectoryContents method. If you have Visual Studio 2005 they've given you a great head start on this with the pre-built Explorer Form
displaying the content(files) of a directory with a button click
displaying the content(files) of a directory with a button click
gjutras
thanks anyways :)
John A Grandy
Hello. Depending on your version of Visual Studio and how far you want to go you might want to add a listbox and in the button's click event do something like the following
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickShowDirectoryContents("c:\root\sample")
End Sub Private Sub ShowDirectoryContents(ByVal path As String) For Each foundFile As IO.FileInfo In New IO.DirectoryInfo(path).GetFiles Me.ListBox1.Items.Add(foundFile.FullName) Next End SubA slightly more advanced approach might fill up a treeview with the full path hierarchy of your drives and in the AfterSelect event make a call to the ShowDirectoryContents method. If you have Visual Studio 2005 they've given you a great head start on this with the pre-built Explorer Form