Osayz Family

Osayz Family

  • NA
  • 7
  • 4.7k

Can't create a text file in C#

Aug 12 2013 5:52 AM
My app has a Login Form. 
Following code which I created a text file is not correct. I don't know why. 
Error is Access denied in C:\Windows\Apple.txt
And i want this text file to log usernames when user changed his username
Please help me with correct code.
thx C-SharpCorner guys......

using System.IO;

string fileLocation = @"C:\Windows\Apple.txt";
                
if (!File.Exists(fileLocation))
{
       FileStream xFile = new FileStream(fileLocation, FileMode.CreateNew);
       StreamWriter sw = new StreamWriter(xFile);
       sw.Write(this.txtUsername.Text);
       sw.Close();
}

Answers (3)