using System.IO; // Include namespace at top of project
Tip: to program defensively, check first if the folder exists (or currently available on the network).
// Use '@' for C# string literals to avoid escaping backslashes (n/a for VB)
string folder = @"C:\Projects\Notes";
string[] textFiles = Directory.GetFiles( folder, ".txt" );
MessageBox.Show( "Found " + textFiles.Length.ToString() + " text files" );
Note: the file extension filter is case-insensitive (passing *.txt yields same listing as *.TXT).
Directory.GetFiles( folder, ".TXT", SearchOption.TopDirectoryOnly );
string name = "";
for( int i=0; i < textFiles.Length; ++i ) {
name = textFiles[i].Substring( textFiles[i].LastIndexOf("\\")+1 );
dropdown.Items.Add( name );
}
Tip: to hide file extensions, append .Replace( “.txt”, “” ) after the assignment to name (line 3).