A ListBox lists all the folders & files existing in a directory named
MyDir on the server. Assume that the ListBox lists 2 directories - Dir1 &
Dir2 i.e. these 2 directories reside in the MyDir directory. Both
Dir1 & Dir2 also house sub-directories & files. Assume that the sub-directory
Dir1 has 3 directories & 3 files.
When a user comes to a ASPX page for the first time, the ListBox lists all the directories & files existing in
MyDir. As expected, the ListBox also lists the 2 sub-directories Dir1 &
Dir2.
What I want is when a user selects, say, Dir1 from the ListBox & clicks a Button, then the ListBox should now list the directories & files existing in
Dir1 so that the user can view all the directories & files residing in
Dir1.
How do I do this?
Thanks
RON
*********
If you have an apple & I have an apple & we exchange our apples, then each of us will still have only 1 apple but if you have an idea & I have an idea & we exchange our ideas, then each of us will have 2 ideas
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
getdirectoryinfo("C:\")
End If
End Sub
Sub getdirectoryinfo(ByVal path As String)
Dim files As FileInfo()
Dim folders As DirectoryInfo()
Dim di As New DirectoryInfo(path)
files = di.GetFiles()
folders = di.GetDirectories
linkbackbutton.Text = path
Me.listfiles.Items.Clear()
For i As Integer = 0 To folders.Length - 1
Me.listfiles.Items.Add(New ListItem("d - " & folders(i).Name, "d" & "|" & folders(i).FullName))
Next
For i As Integer = 0 To files.Length - 1
Me.listfiles.Items.Add(New ListItem("f - " & files(i).Name, "f" & "|" & files(i).FullName))
Next
End Sub
Sub getinformation()
If Not Me.listfiles.SelectedIndex = -1 Then
Dim values As String() = Me.listfiles.SelectedValue.Split("|")
If values(0) = "d"Then
getdirectoryinfo(values(1))
Else'###############
'## Do something with the file, show it, open it in a new window, something
End If
End If
End Sub
Protected Sub btngetinfo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btngetinfo.Click
getinformation()
End Sub
Sub GoBack()
Dim di As New DirectoryInfo(Me.linkbackbutton.Text)
getdirectoryinfo(di.Parent.FullName)
End Sub
Protected Sub linkbackbutton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles linkbackbutton.Click
If Not Me.linkbackbutton.Text = "C:\"Then
GoBack()
End If
End Sub
RN5A
Participant
961 Points
406 Posts
Browse Sub-Directories
Jan 09, 2007 09:26 PM|LINK
When a user comes to a ASPX page for the first time, the ListBox lists all the directories & files existing in MyDir. As expected, the ListBox also lists the 2 sub-directories Dir1 & Dir2.
What I want is when a user selects, say, Dir1 from the ListBox & clicks a Button, then the ListBox should now list the directories & files existing in Dir1 so that the user can view all the directories & files residing in Dir1.
How do I do this?
RON
*********
If you have an apple & I have an apple & we exchange our apples, then each of us will still have only 1 apple but if you have an idea & I have an idea & we exchange our ideas, then each of us will have 2 ideas
RichardMathi...
Participant
755 Points
166 Posts
Re: Browse Sub-Directories
Jan 09, 2007 10:19 PM|LINK
how about this
for the front.
<div><asp:LinkButton runat="server" ID="linkbackbutton" /></div> <asp:ListBox runat="server" ID="listfiles" /> <div><asp:Button runat="server" ID="btngetinfo" Text="Show Information" /></div>for the backsystem.io
Dndorks Webmaster
http://dndorks.com/
TopWebcomics Webmaster
http://topwebcomics.com/