Hi, I knew before, the coding to write from a textbox to a textfile and read from one and similar thigns to it. But I lost all my projects and i forgot how to do it.
What I'm trying to do is a have the information the user inputs into a textbox have it saved into a text file. I thoguth I was getting the process right but I kept getting this error:
"The process cannot access the file 'C:\Users\MomDad\Desktop\username.txt' because it is being used by another process."
I was using this code below. Also, I'm tryign to have it to that when the user checks the checkbox, it will save the information he entered into the textfile which will be created:
if (File.Exists(d + @"\username.txt") == false)
{
File.Create(d + @"\username.txT");
string un = d + @"\username.txt";
using (StreamWriter sw1 = new StreamWriter(un))
{
sw1.Write(textBox1.Text);
sw1.Close();
}
}
else
{
File.Delete(d + @"\username.txt");
File.Create(d + @"\username.txT");
string un = d + @"\username.txt";
using (StreamWriter sw1 = new StreamWriter(un))
{
sw1.Write(textBox1.Text);
sw1.Close();
d by the way, just stands for the desktop directory string. string d = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
The code of line highlights where I start 'using' with the error I described above. I think I'm missing something but I don't know what it is.
Thanks for the help in advance!