I written the code for deleting temp file from the system when we logout the application
This code work in localhost
But when i deployed the application on server it is giving the error
Access Denied C:/Window/Temp
I given full rights to this directory
The code is below
string path = Path.GetTempPath();
object[] files = Directory.GetFiles(path);
foreach (string file in files)
{
FileInfo fi = new FileInfo(file);
if (!IsFileOpen(fi))
{
File.Delete(file);
}
}
private bool IsFileOpen(FileInfo file)
{
try
{
FileStream fs = new FileStream(file.ToString(), FileMode.Open);
fs.Close();
return false;
}
catch (IOException)
{
return true;
}
}
Can anyone Please tell me how to solve this problem