File permissions in C#

王林
Release: 2023-09-08 21:29:02
forward
985 people have browsed it

C# 中的文件权限

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-

1
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-

##1 2 3 4
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.

Let’s see an example of using the FileIOPermission class in C#. Here, the Demand() method forces a SecurityException to be thrown at runtime if all callers higher up in the call stack have not been granted the permissions specified by the current instance -

Example

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); } } }
Copy after login

The above is the detailed content of File permissions in C#. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!