Hi,
i created the following code and that's working:
private void loadFilesDataSet ()
{
string [] files = Directory.GetFiles
("C:\\inetpub\\wwwroot\\aspnet\\Documents\\");
object [] values;
System.Data.DataTable filestable = new DataTable ("Files");
filestable.Columns.Add (new DataColumn ("Filename", typeof
(string)));
for (int counter = 0; counter < files.Length; counter++)
{
if (files [counter].EndsWith (".doc") || files
[counter].EndsWith (".doc"))
{
values = new object [] {Path.GetFileName (files
[counter])};
filestable.Rows.Add (values);
}
}
DataSet test = new DataSet ("Filenames");
test.Tables.Add (filestable);
DataView abc = test.Tables [0].DefaultView;
DropDownList4.DataSource = abc;
DropDownList4.DataTextField =
abc.Table.Columns["Filename"].ColumnName.ToString();
DropDownList4.DataBind();
return;
}
--
thanks,
Remco Ploeg
"ha**********@gmail.com" wrote:
Hi,
The way to do this is to set the DataSource property of the
DropDownList with the list of files. Once you do that, then you want to
tell the DropDownList what properties of the FileInfo class it should
use as the Text and Value attributes of the DropDownList. Here is the
code that you need:
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
// set the path to your directory here
DirectoryInfo di = new DirectoryInfo(@"C:\");
FileInfo[] fis = di.GetFiles();
DropDownList1.DataSource=fis;
DropDownList1.DataTextField="Name";
DropDownList1.DataValueField="Name";
DropDownList1.DataBind();
}
}
Thanks,
Sayed Y. Hashimi
http://www.sayedhashimi.com
Shameless Book Plug: Service-Oriented Smart Clients with .NET 2.0
http://www.amazon.com/exec/obidos/tg...glance&s=books