Checking file and folder access permissions
In every organization, we have multiple departments and sections; every department and section has their own role and permission matrix to access the filesystem. If we are accessing files and folders that are under access control it is very important to check access rights to our file which will be accessed by the system. We can carry out this activity manually and set the rule. Still, let's take a look at this recipe to check the access permission by code.
How to do it...
Create a new
Class Library
project in Visual Studio and follow the steps.Create a new file with the following code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Security.Permissions; using System.Runtime.InteropServices; namespace FolderAccess { [ClassInterface(ClassInterfaceType.AutoDual)] [ProgId("FolderAccess")] [ComVisible(true)] public class FolderAccess { public bool TestFolderAccess(string...