1
我正在製作一個項目,該項目使用條形碼來存儲與項目有關的信息。對於每個條形碼,都有一個包含其信息的文本文件。例如,條形碼0000000025將其所有信息存儲在名爲0000000025.txt的文件中。我希望能夠將條形碼輸入到文本框中,並根據條形碼告知StreamReader要從中讀取哪個文件。代替手工編碼300,如果是這樣else語句:StreamReader("C:\\ITRS_equipment_log\\0000000025.txt");
在C中更改StreamReader文件擴展名#
有沒有辦法告訴它
StreamReader("C:\\ITRS_equipment_log\\"*pull the barcode from the first textbox and put it here*".txt");
感謝
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();
}
}
謝謝!完美地工作! – McAfeeJ 2012-04-10 01:32:58