tags:

views:

41

answers:

1

I have two programs which are accessing a directory using the .NET Directory class static methods.

The first program is only reading a directory, while the second is attempting to rename a directory. The directory being renamed by the second program may not be the same directory that is being read by the first program.

When the second program attempts to rename the directory (i'm using the Directory.Move(sourceDir, destDir) function ), I get an error like:

system.io.exception access to the path is denied

I suspect that the reason this is happening is that I should be using DirectoryInfo methods (which are instance, not static). Has anyone run into this problem before?

A: 

As far as I can tell, the solution to my problem was to use System.IO.DirectoryInfo objects instead of using the static System.IO.Directory class. The only clues I could find as to why this solves my problem is here where it says that security checks do not happen on all methods in an instance of DirectoryInfo but the security checks always happen for methods called by the static Directory class.

Even though this solves my problem, it does not give me enough information on why this works. If anyone can give me more information, I would be grateful.

David