System.Security.Permissions.FileIOPermissionAttribute Class
Used to declaratively specify security actions to control access to files and directories.

See Also: FileIOPermissionAttribute Members


[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.All, AllowMultiple=true, Inherited=false)]
public sealed class FileIOPermissionAttribute : CodeAccessSecurityAttribute



The level of access to a file or directory is specified using the members of the current instance. For example, to specify read permissions for a file, set the FileIOPermissionAttribute.Read property equal to the name of the file.

The security information declared by a security attribute is stored in the metadata of the attribute target, and is accessed by the system at run-time. Security attributes are used for declarative security only. For imperative security, use the corresponding permission class, System.Security.Permissions.FileIOPermission.

The allowable System.Security.Permissions.FileIOPermissionAttribute targets are determined by the System.Security.Permissions.SecurityAction passed to the constructor.

Case-sensitivity of file and directory names is platform dependent. The set of characters that are valid for use in file and directory names is determined by the current file system.

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.


The following example shows a declarative request for full access to the specified file. The SecurityAction.RequestMinimum security action indicates that this is the minimum permission required for the target assembly to be able to execute.

[assembly:FileIOPermissionAttribute(SecurityAction.RequestMinimum, All="\\example\\sample.txt")]

The following example shows how to demand that the calling code has unrestricted access to files and directories. Demands are typically made to protect methods or classes from malicious code.

[FileIOPermissionAttribute(SecurityAction.Demand, Unrestricted=true)]


Namespace: System.Security.Permissions
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0,,