Environmental variable %Username%
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];
}
}
}

Roei BarRank #1,271 · 1.4K reputationPosted Sep 1, 2009, 2:51 PM EDT
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(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).ToString() + @"/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]; } } }