I am making a project that uses barcodes to store information relating to the item. For each barcode, there is a text file that contains its information. An example is barcode 0000000025 has all of its information stored in a file called 0000000025.txt. I want to be able to enter the barcode into the textbox and it tells the StreamReader which file to read from based on the barcode. Instead of hand coding 300 if else statements like this: StreamReader("C:\\ITRS_equipment_log\\0000000025.txt");
Is there a way to tell it
StreamReader("C:\\ITRS_equipment_log\\"*pull the barcode from the first textbox and put it here*".txt");
Thanks
private void buttonSubmit_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(textBox1.Text))
{
textBox1.SelectionStart = 0;
textBox1.SelectionLength = textBox1.Text.Length;
TextReader textReader = new StreamReader("C:\\ITRS_equipment_log\\0000000025.txt");
//model textbox receives the model of equipment associated with barcode in the text file
modelTextbox.Text = textReader.ReadLine();
//serial textbox receives the serial number of equipment associated with barcode in the text file
serialTextbox.Text = textReader.ReadLine();
//history textbox receives the history of equipment associated with barcode in the text file
historyTextbox.Text = textReader.ReadToEnd();
textReader.Close();
}
}
This should insert the barcode text into the file name for you: