Mayur  Gujrathi

Mayur Gujrathi

  • 409
  • 3.9k
  • 1m

Creating and writting file

Dec 20 2011 7:41 AM
string path = "C:\\mytest.txt";
 

 
            if (File.Exists(path))
            {
                File.Delete(path);
            }
 

            using (FileStream fs = File.Create(path))
            {
                //fs.Close();
              // fs.CanWrite = true;
          TextWriter sw = new StreamWriter("C:\\mytest.txt");//error is coming here
          sw.WriteLine("ddd", "dddd", "dsdsd");
          --------------
          -------------
          --------
            }
 
I am trying to create and write to text file but is giving error file is being used by another person

Answers (3)