Click here to Skip to main content
14,668,708 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello all.

I have a question on the Using statement in C# e.g.

using (FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))

Occasionally, as I loop through the near 6 million docs on a Windows server I will get an Access Denied exception

This occurs where a specific network group has not been added to the files ACL. Why this situation, which should never be the case, occurs is perplexing but I'll save that for later investigation.

When it does occur I can use XCACLS from the development PC, in a local CMD box, to add the network group to the files ACL, no problems.

My question is, while running in debug mode (VS 2005), is VS running in a different Security Principle than my account ? (Hence this exception ?)


The environment is configured like so:

Document store ----

Windows Server 2003 64bit, shared folder where the DOCS_ADMIN group has full rights at share and folder level

I'm also in another group which is a member of the Administrators on this server.

Local PC:

Crappy XP with VS 2005

Why I am doing this is that many users have imported 2007 Office files into the Doc Management System as Office 2003 files - and then finding that they cant read the files, since the DM app kindly renames the extension. So I have to trawl through the document store looking at the file's signature to see if it's actually an Office 2007 file. (To be fixed later)

If it is running in a different security context I may be able to code around it in the Try/Catch block.

Cheers,
DB
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

The debugger should not run in another security context. You could try the link below to check the access rights and can also use this to check which account is used for this. It could also be that the server (or another user) is currently performing some operation on the file.

You could try to check the access rights, try to open and log any files locked. (you could also create a collection of files that could not be accessed and try those again later) When you log this information to a log file you can also see if these exceptions where also raised when not in debug mode and simply silently discarded and undetected.

Check User Permissions On A File or Folder[^]

Good luck!
   
Comments
DABBee 25-Sep-10 19:53pm
   
Reason for my vote of 5
Automatic vote of 5 for accepting answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100