File Searcher in VB.NET

Hi! Today, we will have a tutorial on how to create a file searcher program that can access to search files to your computer and display the lists of corresponding file in the ComboBox. So, now let's start this tutorial! 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 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: design 3. Put this code to your Button1_Click. This will trigger to search a corresponding file to your input in textbox.
  1.   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim files As Object
  3.         Try
  4.             For Each files In My.Computer.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.Desktop, FileIO.SearchOption.SearchAllSubDirectories, Nothing)
  5.                 Dim foundFile As String = My.Computer.FileSystem.GetFileInfo(files).Name()
  6.                 If foundFile.Contains(TextBox1.Text) Then
  7.                     ComboBox1.Items.Add(foundFile)
  8.                 End If
  9.             Next
  10.         Catch ex As Exception
  11.             MsgBox("File doesn't exist.")
  12.         End Try
  13.     End Sub

Explanation:

As you can see, we initialized a Try and Catch statement to filter the searching of files. We have initialized files as variable to be our object. We used this variable in our for-each loop. My.Computer.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.Desktop, FileIO.SearchOption.SearchAllSubDirectories, Nothing) - 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. Next, the FileIO.SearchOption.SearchAllSubDirectories means that we will search a corresponding file, and the Nothing here means that there is no default file to search. Next, we have initialized foundFile to hold the File information of our files variable. If the input in your textbox contains the value of foundFile, it will add the items or files in the combobox. Otherwise it will prompt the user, File doesn't exist.

Output:

output output Download the source code below and try it! :) 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 R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz

Add new comment