Checking file and folder access permissions
Many systems have batch processes which read and write files to folders on the file system. In order to avoid some of the standard Windows error messages and prevent errors in the middle of the process you may want to check access permissions.
How to do it...
Create a new Class Library project in Visual Studio.
Create a new file with the following code:
using System; using System.Security.Permissions; using System.Runtime.InteropServices; namespace FolderAccess { [ClassInterface(ClassInterfaceType.AutoDual)] [ProgId("RegistryQuery")] [ComVisible(true)] public class FolderAccess { public bool TestFolderAccess(string folder, string access) { System.Security.Permissions.FileIOPermissionAccess accessLevel; switch (access.ToUpper()) { case "NOACCESS": accessLevel = FileIOPermissionAccess.NoAccess; break; case "READ": accessLevel = FileIOPermissionAccess.Read; break; case "WRITE": accessLevel = FileIOPermissionAccess.Write; break; case "APPEND": accessLevel...