Windows Phone Developers

Saturday, November 1, 2008

C# Get All Files from a Folder

List all files from a folder using C# / List all files from folder and its subdirectories using C#

The following code lists all the files from the specifed folder and its sub folders

To list all Excel files using C#, modify the first argument to “*.xls”

private static void GetFilesFromDirectory(string DirPath)




DirectoryInfo Dir = new DirectoryInfo(DirPath);

FileInfo[] FileList = Dir.GetFiles("*.*", SearchOption.AllDirectories );

foreach (FileInfo FI in FileList )





catch (Exception ex)


Console.WriteLine(ex.Message );



The following wildcard specifiers are permitted in searchPattern.

Wildcard character



Zero or more characters.


Exactly one character.

Search for Word files starting with “Proposal” using C# in Current Directory

FileInfo[] FileList = Dir.GetFiles("Proposal*.doc", SearchOption.TopDirectoryOnly );

SearchPattern for files in C#, C# Dir Function SearchPatterns, List All files using C#, C# Dir Function, C# List of Files, How to get the list of files using C#,

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

1 comment:

  1. How to get all .xls files(files may be more than 50 ) from a folder and display those Excel datas (Datas may be more than 50 ) into a grid or ListBox.