C
C#2y ago
Milk

❔ "cant open file due to it being used by another process"

The process cannot access the file 'C:\Users\user\source\repos\Clickity\Clickity\bin\Debug\net6.0-windows\score.txt' because it is being used by another process
The process cannot access the file 'C:\Users\user\source\repos\Clickity\Clickity\bin\Debug\net6.0-windows\score.txt' because it is being used by another process
private void button4_Click(object sender, EventArgs e)
{
System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(sPath);
foreach (var item in listBox1.Items)
{
SaveFile.WriteLine(item.ToString());

}
SaveFile.Close();
}

private void button5_Click(object sender, EventArgs e)
{
System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(sPath);
string[] lines = File.ReadAllLines(sPath);

foreach (string line in lines)
Console.WriteLine(line);
SaveFile.Close();
}
private void button4_Click(object sender, EventArgs e)
{
System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(sPath);
foreach (var item in listBox1.Items)
{
SaveFile.WriteLine(item.ToString());

}
SaveFile.Close();
}

private void button5_Click(object sender, EventArgs e)
{
System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(sPath);
string[] lines = File.ReadAllLines(sPath);

foreach (string line in lines)
Console.WriteLine(line);
SaveFile.Close();
}
what im trying to do here is basically just write and read to a specific file. rather confusing
4 Replies
Buddy
Buddy2y ago
You cannot write to a file simultaneously. Why are you opening a StreamWriter when you just want to read?
System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(sPath);
string[] lines = File.ReadAllLines(sPath);

foreach (string line in lines)
Console.WriteLine(line);
SaveFile.Close();
System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(sPath);
string[] lines = File.ReadAllLines(sPath);

foreach (string line in lines)
Console.WriteLine(line);
SaveFile.Close();
Specifically this snippet
Milk
MilkOP2y ago
ah i see i love my observing skills
Buddy
Buddy2y ago
😉
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server