File Searcher in C#
Submitted by donbermoy on Thursday, June 19, 2014 - 16:33.
Today in C#, I will teach you how to create a program that will search for a file in a specific path using C#. But here, we will only search for a file in the desktop.
So, now let's start this tutorial!
1. Let's start with creating a Windows Form Application in C# for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application and name your program as File Searcher.
2. Next, add one TextBox named TextBox1 for inputting a file to search,add one button named Button1 for finding the inputted file on the textbox and labeled it as "Search", and lastly add a combobox named combobox1 to show or display the corresponding files. Design your layout like this one below:
3. Put this code to your Button1_Click. This will trigger to search a corresponding file to your input in textbox.
Output:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

- public void Button1_Click(System.Object sender, System.EventArgs e)
- {
- //We have initialized files as variable to be our object. We used this variable in our for-each loop.
- object files = default(object);
- //initialize a Try and Catch statement to filter the searching of files.
- try
- {
- //this GetFiles Method will get a corresponding file from the directoories of our desktop as we put My.Computer.FileSystem.SpecialDirectories.Desktop, thus, it will get a file from the Desktop Directory
- {
- // the files variable will now hold the value of the tempLoopVar_files that will get the files in the desktop
- files = tempLoopVar_files;
- // Create variable foundFile that will get the file information with its file name only
- string foundFile = (string) ((new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.GetFileInfo(files.ToString()).Name);
- // If the searched file name is found, it will display all the related file name in the desktop and will have it in the ComboBox
- if (foundFile.Contains(TextBox1.Text))
- {
- ComboBox1.Items.Add(foundFile);
- }
- }
- }
- // If the inputted searched file is not found, then it will prompt the user "File doesn't exist."
- catch (Exception)
- {
- MessageBox.Show("File doesn't exist.");
- }
- }


Add new comment
- 137 views