Search code examples
file-ioc#-3.0access-denied

File access denied, c# console application error


This is a really odd security issue with a C# (3.0) Console application.

The application creates a folder and copies a bunch of files into that folder, it then also generates some files and saves them into the same folder. File streams are always closed. The copied files are done using File.Copy. Once the files are there, I don't seem to be able to access them again - later in the code, if I want to delete or open an existing file I get a access denied error yet I just created or copied the file there so I know I have permission!

Visual Studio 2008, Windows 7 (beta) - tried running as administrator but it didn't help. I also gave the parent folder permissions so that "Everyone" had write access and its under my logged in user documents folder.

Thanks!

update: I tried this on XP and had the same result so its not Win 7 :)


Solution

  • Have the files got the read-only attribute set? Trying to delete read-only files can cause an access denied exception to be thrown.