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

In temp folder some of the files are working with relative links..and so it is opened for working...so when you try for delete using code then it shows some of the files are opened and cannot deleted...solution is...restart your computer and the run this code...it will work