Directory Browsing

G

Guest

Hi Guys,
I am currently programming in Vb .net. I am stuck at point. i have a root
directory
C:\test
which has couple of sub-folders c:\test\test1 ; c:\test\test2 ;
c:\test\test1\test4 and so on.

I need to create a list box with parent directory and its sub directories
below it for all the folders inside the root directory and sub-folders etc.
I have tried numerous approaches, can someone please tell me how to get this
done. Any articlet that i can take a look at?

Thanks

manny
 
D

Derek Harmon

Manny Chohan said:
I have tried numerous approaches, can someone please tell me how to get this
done.

What have you tried so far?
I need to create a list box with parent directory and its sub directories
below it for all the folders inside the root directory and sub-folders etc.

Have you tried databinding the ListBox to the array of subdirectories
returned from the Directory.GetDirectories( "C:\test") function call?
Then add "C:\test" manually.
Any articlet that i can take a look at?

http://msdn.microsoft.com/library/e...systemiodirectoryclassgetdirectoriestopic.asp

Don't forget to ensure your ASPNET user account has the security
permissions granted to discover these paths, or you'll receive a
SecurityException.


Derek Harmon
 
K

Karl Seguin

Manny:
The quickest solution I could come up with was:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim list As ArrayList = GetDirectories("c:\test")
ddl.DataSource = list
ddl.DataBind()
End If

End Sub

Public Shared Function GetDirectories(ByVal path As String) As ArrayList
Dim list As New ArrayList
For Each subs As String In IO.Directory.GetDirectories(path)
list.Add(subs)
list.AddRange(GetDirectories(subs))
Next
Return list
End Function


hopefully it gives you a place to start...

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top