R
rn5a
I have a ListBox which should list all the files & directories that
exist in a particular directory. The problem is I can get the ListBox
to list either all the files or all the directories but not the 2 of
them together. This is what I tried:
Sub Page_Load(.....)
Dim dInfo As DirectoryInfo
dInfo = New DirectoryInfo(Server.MapPath(MyDir))
'get all the directories existing in MyDir
lstFilesDirs.DataSource = dInfo.GetDirectories
'get all the files existing in MyDir
lstFilesDirs.DataSource = dInfo.GetFiles
lstFilesDirs.DataBind()
End Sub
<form runat="server">
<asp:ListBox ID="lstFilesDirs" runat="server"/>
</form>
In the above code, since the GetFiles method has been issued after the
GetDirectories method, the ListBox lists only the files existing in the
directory named MyDir. On the other hand, had the GetFiles method been
issued after the GetDirectories method, then the ListBox would have
listed only the directories existing in the directory MyDir. So the
ListBox lists either all the files or all the directories existing in
the directory named MyDir.
How do I list all the directories as well as all the files existing in
the directory MyDir in the ListBox?
exist in a particular directory. The problem is I can get the ListBox
to list either all the files or all the directories but not the 2 of
them together. This is what I tried:
Sub Page_Load(.....)
Dim dInfo As DirectoryInfo
dInfo = New DirectoryInfo(Server.MapPath(MyDir))
'get all the directories existing in MyDir
lstFilesDirs.DataSource = dInfo.GetDirectories
'get all the files existing in MyDir
lstFilesDirs.DataSource = dInfo.GetFiles
lstFilesDirs.DataBind()
End Sub
<form runat="server">
<asp:ListBox ID="lstFilesDirs" runat="server"/>
</form>
In the above code, since the GetFiles method has been issued after the
GetDirectories method, the ListBox lists only the files existing in the
directory named MyDir. On the other hand, had the GetFiles method been
issued after the GetDirectories method, then the ListBox would have
listed only the directories existing in the directory MyDir. So the
ListBox lists either all the files or all the directories existing in
the directory named MyDir.
How do I list all the directories as well as all the files existing in
the directory MyDir in the ListBox?