Browser Sub-Directories

R

rn5a

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?
 
L

Laurent Bugnion [MVP]

Hi,

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
 

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,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top