Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select filename in drop down menu

Status
Not open for further replies.

aspdotnetuser

Programmer
Oct 10, 2008
45
GB
Hi,

How can I read file names from a folder to allow users to select a file name?

I'm guessing the code would look something like:

[blue]int FileNum = File.Open(@"c:\DinerDocs\SavedEmailTemplates\", FileMode.Open).Length;

(while FileNum > 0){[/blue]
[red]//Add filenames to dropdown list
//Get filename[/red]
[blue]DropDownList1.Items.Add(FileName.ToString());
}[/blue]
 
I just realised you can do this using the following code:

[blue]string[] fileEntries = Directory.GetFiles(Folder path goes here);
foreach (string fileName in fileEntries)
{
// do something with fileName
DropDownList1.Items.Add(fileName.ToString());
}
}[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top