470,819 Members | 1,621 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,819 developers. It's quick & easy.

Browser Sub-Directories

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?

Jan 9 '07 #1
1 1548
Hi,

rn**@rediffmail.com wrote:
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?
You have two things to consider:

1) How does the client react when the user clicks on Dir1?
2) What does the server have to do?

1) On the client, the easiest way is to post a request to the server,
and to refresh the page. It's the easiest because you don't have to do
anything, ASP.NET does the work for you. If you set AutoPostBack = true,
clicking on the ListBox will automatically generate a POST for you.

2) On the server, the easiest way is to use the ListBox'
SelectedIndexChanged event. In your event handler, you can then modify
the content of the ListBox. To get the list of directories and files for
Dir1, you can simply use the same way you did for MyDir.

An alternative is to use a web service to do this without refreshing the
page, however the logic becomes more complex on the client. In that
case, you must use JavaScript to modify the content of the ListBox (on
the client, a ListBox is rendered by a SELECT control).

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jan 10 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by gokul | last post: by
2 posts views Thread by david | last post: by
8 posts views Thread by Joe Johnston | last post: by
8 posts views Thread by Robert | last post: by
16 posts views Thread by Alex Clark | last post: by
15 posts views Thread by tshad | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.