This is a big thing and I’m sure it won’t be needed much, but the library is so large for .Net that sometimes finding out how to do something easy can take MUCH longer then it should. For example I am working on a new app where the user has to pick a directory for processing files. The output needs to be able to write to the directory and create some sub-directories, so I need to check the users permissions on the main chosen directory.
A fairly simple thing, and finding an example on how to do it, not so much.
After much mucking around in the file / directory permissions / ACL IO, which just resulted in UGLY convoluted code that seemed to go around and around the tree without ever actually getting around to marking it, a couple of bing and google searches later and I found this link :how do you check for permissions to write to a directory or file.
basically you need to determine the type of permission you want, then ask the SecurityManager static library “IsGranted”.
var writePerm = new System.Security.Permissions.FileIOPermission(FileIOPermissionAccess.Write, dirPath);
(System.Security.SecurityManager.IsGranted(writePerm)