How to get list of all folders in a DropdownList in asp.net

Description:-

Get list of all folders in a Dropdownlist. using Directory class we can bind or get directories from Drive and bind into where we want. Here I have bind E: Drive all folder in dropdownlist control.

Default.aspx:-

<div>
  <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
</div>

Default.aspx.cs:-

protected void Page_Load(object sender, EventArgs e)
{
  foreach (var folder in Directory.GetDirectories(@"E:\"))
  {
    DropDownList1.Items.Add(folder.ToString().Replace(@"E:\", ""));
  }
}

Related Posts

Thanks for comments.....

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
:-?
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
$-)
(y)
(f)
x-)
(k)
(h)
cheer