المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : The process cannot access the file because it is being used by another process.



C# Programming
06-23-2009, 07:12 PM
Hi I am writting the following code to write into text file.After Checking whether the file exixt or not ,It is giving the following error.Can any one help.

Any solution to this problem would be appreciated.

public void Ping(string hostName)
{
string path;

path = @"C:\CheckList\checklist_"+DateTime.Now.ToString("yyyyMMdd")+".txt";

if (!File.Exists(path))
{

File.Create(path);


}


TextWriter tw = new StreamWriter(path,true);

Error comes when we create text writer.