C#C
C#3y ago
8 replies
Sir Milo

❔ "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

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
Was this page helpful?