string FilePath = @"D:\WebSite1\Folder\open.txt";
try
{
System.IO.File.CreateText(FilePath);
bool fileExist = false;
while (!fileExist)
{
FileInfo sFile = new FileInfo(@"D:\WebSite1\Folder\close.txt");
fileExist = sFile.Exists;
}
System.IO.File.Delete(@"D:\WebSite1\Folder\open.txt");
System.IO.File.Delete(@"D:\WebSite1\Folder\close.txt");
}
catch (Exception ex)
{
}
above code throws ex of The process cannot access the file 'D:\\WebSite1\\Folder\\open.txt' because it is being used by another process.