Some more thoughts on this issue:

 

The comments about the file system permissions being unpredictable are dead
right. If you're working with folders and files used by other apps or people
then you're flying blind and anything can happen. File might vanish or
appear, drive letter unmapped, permissions can change, etc.

 

I normally tackle the question of "do I have file system permissions?" at
install time. I have a Custom Action that runs the ICacls command as
necessary during install, so my code trusts the installer and assumes that
it has permission to write to where it expects to. If it can't, then it's a
serious problem in the environment or a human error.

 

Avoid the problem by only writing to known folders with known permissions as
specified in the Environment.SpecialFolder enumeration.

 

I haven't tried using the System.Security.AccessControl
<http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.aspx>
namespace for this specific purpose, but it has all of the ACE and ACL
wrappers that can probably tell the real truth about whether you can read,
write and delete from a folder. You'd still have to defend against timing
problems and external interference.

 

Greg

Reply via email to