For file permissions in C#, use the FileIOPermission class. It controls the ability to access files and folders.
The following are the attributes of the file permission class-
Sr.No. | Methods and instructions |
---|---|
AllFiles Gets or sets allowed access to all files. |
|
2 | AllLocalFiles Gets or sets allowed access to all local files. |
The following are the methods of the file permission class-
Mr. | Methods and descriptions |
---|---|
AddPathList(FileIOPermissionAccess, String)This method Adds access to the specified file or directory to the existing state of permissions | |
Copy()This method creates and returns an identical copy of the current permissions. | |
GetType()GetType() method gets the current type Example. | |
ToXml()Create an XML encoding of permissions and its Current status. |
using System; using System.IO; using System.Security.Permissions; using System.Security; public class Demo { public static void Main() { FileIOPermission file= new FileIOPermission(PermissionState.None); file.AllLocalFiles = FileIOPermissionAccess.Read; try { Console.WriteLine("Demands the permission to determine whether the application has permission to read the files"); file.Demand(); } catch (SecurityException s) { Console.WriteLine(s.Message); } } }
The above is the detailed content of File permissions in C#. For more information, please follow other related articles on the PHP Chinese website!