TextSearch-1.0 reveals the track to enhance the search functionality of Text Documents belonging to the same path/folder.
Description
TextSearch-1.0 allows users to search for a specific word from many text documents (File Format: *.txt) that belongs to the same directory, with no need to open individual files to search for a word or text. It has a simple GUI.
About the classes used:
- The FolderBrowserDialog class allows users to select a folder.
- The Directory class allows a user to enumerate the files available at a specified directory path.
- The StreamReader class provides a access for reading the data from a Stream such as a Text File.
- The Process class, to allow a user to start a specific process.
Namespace Required
System.IO,
System.Diagnostics
Controls Used
The controls that are used are:
- TextBox Control (txtFolder, txtSearch)
- ListBox Control (lbFiles)
- Button Control (btnFolder, btnSearch, btnReset)
Here I present the code for finding a text file(s) with a specified word or text provided as a search string.
The Code
1. Variable Declarations:
String target = ""; // Target string to Search
String path = ""; // Path of Directory
string[] files; // Store file name(s) from given path
bool search; // Determine whether Target string present or NOT
string[] list; // Store file name(s) which includes Target string
Listing 1
2. List All Text File(s) (File Format: *.txt)
void getFiles()
{
lbFiles.Items.Clear(); //Clears the Previous file list (if any)
path = txtFolder.Text; //Current path of selected folder
if (path != ""){
// Collects the name of files with extension of ".txt"
files = Directory.GetFiles(@path, "*.txt");



Join the conversation! Your thoughts help the community grow.