matthew king

matthew king

  • NA
  • 52
  • 0

environmental variable %Username%

Sep 1 2009 4:17 PM
Sir/Ma'am, I was hoping one of you could assist me with what is probably an easy question. I'm using streamreader to search a txt file, and it works great. However, it just dawned on me that this particular txt file is stored on each of my user profiles: C:/Documents and Settings/%USERNAME%/Application Data/CCMT/ccmtlog.txt For the life of me, I can't figure out how to set an environmental variable in c#. I would appreciate your help.. private void button1_Click(object sender, EventArgs e) { string line; // Read the file and display it line by line. System.IO.StreamReader file = new System.IO.StreamReader(@"C:/Documents and Settings/%USERNAME%/Application Data/CCMT/ccmtlog.txt"); while ((line = file.ReadLine()) != null) { Console.WriteLine(line); string[] lineStrings = line.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (lineStrings.Length > 1) { if (lineStrings[0] == textBox1.Text) { textBox3.Text = lineStrings[1]; } } }

Answers (1)