0

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

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by crishlay
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.