views:

4611

answers:

3

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 :)

+1  A: 

If you do all your stream declarations in a using block, you should be guaranteed they aren't causing the problem.

Austin Salonen
For streams yes but for File.Copy/Move/Delete operations there is no need and these fail too. I think its a Win 7 bug.
typemismatch
It's worth trying - even though Win7 is in beta, it's still much more likely it's an issue with *your* code than with the OS.
Daniel Schaffer
+3  A: 

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

Mun
you nailed it! some files were copied from an old VSS controlled folder and had read only attributes. thanks :)
typemismatch
No probs. This one got me as well a few months ago, and took me a couple of hours to figure out :-)
Mun
+1 for being a wild guess that worked
kurast
A: 

Flush the files and Close it

A.EL