I have some code that does the following:
1. look for directory - if it exists, delete it
2. create the directory
3. create a new textfile in the directory
Now the code works perfect - it does just what it should except it only works for maybe 2 runs and then it roadblocks with an Access Denied error message on the directory. I can't even get into the directory as an administrator user on the system anymore, it's completely locked. Nothing in my code or the filesystem changes between runs so what could be the problem? And how in the world can i get rid of those locked directories?
1. look for directory - if it exists, delete it
2. create the directory
3. create a new textfile in the directory
Now the code works perfect - it does just what it should except it only works for maybe 2 runs and then it roadblocks with an Access Denied error message on the directory. I can't even get into the directory as an administrator user on the system anymore, it's completely locked. Nothing in my code or the filesystem changes between runs so what could be the problem? And how in the world can i get rid of those locked directories?
Code:
if (Directory.Exists(path))
{
Directory.Delete(path, true);
}
Directory.CreateDirectory(path);
StreamWriter writer = null;
try
{
writer = File.CreateText(Path.Combine(path, "myfile.txt"));
writer.Wrtie("blah");
writer.Close();
}
catch
{
if (writer != null) writer.close
}

