
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
File Permissions in C#
For File Permission in C#, use the FileIOPermission Class. It controls the ability to access files and folders.
The following are the properties of File Permissions class −
Sr.No. | Methods & Description |
---|---|
1 | AllFiles Gets or sets the permitted access to all files. |
2 | AllLocalFiles Gets or sets the permitted access to all local files. |
The following are the methods of File Permission class −
Sr.No. | Methods & Description |
---|---|
1 | AddPathList(FileIOPermissionAccess, String) This method adds access for the specified file or directory to the existing state of the permission |
2 | Copy() This method creates and returns an identical copy of the current permission. |
3 | GetType() The GetType() method gets the type of the current instance. |
4 | ToXml() Creates an XML encoding of the permission and its current state. |
Let us see an example to work wuth FileIOPermission Class in C#. Here, the Demand() method forces a SecurityException at run time if all callers higher in the call stack have not been granted the permission 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); } } }
- Related Articles
- File Permissions in java
- Advanced File Permissions in Linux
- How to change file permissions in Python?
- How to set file permissions in Java?
- How to Copy File Permissions and Ownership to Another File in Linux?
- How to check the permissions of a file using Python?
- Getting root permissions on a file inside of vi on Linux
- Android Runtime Permissions
- MySQL permissions to view all databases?
- Setting Permissions with chown and chmod
- How to Copy NTFS permissions using PowerShell?
- File Handling in C#
- File Objects in C#
- What MySQL databases do I have permissions on?
- Delete a file in C#

Advertisements