Browser Sub-Directories

  • Thread starter Thread starter rn5a
  • Start date Start date
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?
 
What's the problem?

Handle SelectedIndexChanged event of the listbox

Simultaneously, have a hidden field, if need be, whose value would point to
the parent directory whose listing is to be displayed in the listbox.

For example:

hiddenField.Value = "/"; // (/ is the root of the directory -- like MyDir)
listBox.Items.Add(..); // Add all the files and folders

when the form is submitted, do the following:

1. hiddenField.Value = hiddenField.Value + listBox.SelectedValue + "/"; (if
a folder has been selected)
Leave it unchanged if the file was selected

2. listBox.Items.Add(...);
This time, search for the files in the folder "MyDir" +
hiddenField.Value.Replace("/", "\\")

HTH
 
Back
Top