Arun T

Arun T

  • NA
  • 21
  • 6.2k

Error : “The process cannot access the file ''

Apr 17 2014 10:40 AM
 This is my code. Could you please anyone tell me the reason for the error which i mentioned. Using statement usually dispose the object once it went out of scope, but i am getting the error.

public static void WriteLogFile(string message)
        {
            Console.WriteLine(message);

            if (File.Exists("C:\\log.txt"))
            {
                using (StreamWriter SWriter = File.AppendText("C:\\log.txt"))
                {
                    SWriter.WriteLine(message);
                }
            }
            else
            {
                using (StreamWriter SWriter = File.CreateText("C:\\log.txt"))
                {
        
                    SWriter.WriteLine(message);
                }
            }
        }

 

Answers (5)