Monday, May 18, 2009

Search Files in a Directory : Windows Application

Following example I am trying to search files in a directory using a criteria, using DirectoryInfo.GetFiles() method we can search files with Criteria and you can use * to find all files those are starting with the some string.

So lets start building example, create a windows forms application and add one label, text box, a button and list box, please refer following screen shot

image

Add following function to Form1 which takes Search Text as file name and Folder Path where files needs to be searched, In following function I am taking FileName as search text and DirectoryName as folder path and searching the files

image

Double click on Search button add following code, following code I am simply taking the search text and selecting folder path and passing to the above function

image

Now we are ready with Code, lets build, run and test

Output:

image

Tag: DirectoryInfo, FileInfo, C#, Windows Application, Search Files

No comments:

Post a Comment