FileIOPermission 类
控制访问文件和文件夹的能力。无法继承此类。
**命名空间:**System.Security.Permissions
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class FileIOPermission
Inherits CodeAccessPermission
Implements IUnrestrictedPermission
用法
Dim instance As FileIOPermission
[SerializableAttribute]
[ComVisibleAttribute(true)]
public sealed class FileIOPermission : CodeAccessPermission, IUnrestrictedPermission
[SerializableAttribute]
[ComVisibleAttribute(true)]
public ref class FileIOPermission sealed : public CodeAccessPermission, IUnrestrictedPermission
/** @attribute SerializableAttribute() */
/** @attribute ComVisibleAttribute(true) */
public final class FileIOPermission extends CodeAccessPermission implements IUnrestrictedPermission
SerializableAttribute
ComVisibleAttribute(true)
public final class FileIOPermission extends CodeAccessPermission implements IUnrestrictedPermission
备注
此权限区分由 FileIOPermissionAccess 提供的下列四种文件 IO 访问权限类型:
Read:对文件内容的读访问权限或对有关该文件的信息(如它的长度或上次修改时间)的读访问权限。
Write:对文件内容的写访问权限或更改有关该文件的信息(如它的名称)的访问权限。还允许删除和改写。
Append:仅向文件结尾写入的能力。不能读取。
PathDiscovery:对路径本身中的信息的访问权限。这可以保护路径中的敏感信息(如用户名)以及有关路径中显示的目录结构的信息。此值不授予对路径所指代的文件或文件夹的访问权限。
所有这些权限都是独立的,这意味着对其中一个具有权限并不意味着对另一个也具有权限。例如,具有 Write 权限并不意味着具有 Read 或 Append 权限。如果需要多种权限,可以使用按位“或”将它们组合起来,如下面的代码示例中所示。依据规范化绝对路径来定义文件权限;应始终使用规范化文件路径进行调用。
FileIOPermission 描述文件和文件夹上受保护的操作。File 类帮助提供对文件和文件夹的安全访问。当创建文件的句柄时执行安全访问检查。通过在创建时进行检查,将安全检查对性能的影响降到最低程度。打开文件发生一次,而读和写可以发生多次。文件一旦被打开,就不再进行更多的检查。如果将该对象传递给不可信的调用方,则它可能被误用。例如,不应将文件句柄存储在公共全局静态变量中,因为在那里权限极低的代码也能访问它们。
FileIOPermissionAccess 指定可在文件或文件夹上执行的操作。另外,可以使用按位“或”将这些操作组合成复杂实例。
对文件夹的访问是指对它所包含的所有文件的访问,以及对其子文件夹中的所有文件和文件夹的访问。例如,对 C:\folder1\ 的 Read 访问是指对 C:\folder1\file1.txt、C:\folder1\folder2\ 和 C:\folder1\folder2\file2.txt 等等的 Read 访问。
警告
Unrestricted FileIOPermission 授予对文件系统内所有路径的权限,包括可用于访问单个给定文件的多个路径名。若要 Deny 对文件的访问,必须 Deny 该文件所有可能的路径。例如,如果在将 \\server\share 映射到网络驱动器 X 后,要 Deny 对 \\server\share\file 的访问,则必须 Deny \\server\share\file、X:\file 以及可用于访问该文件的所有其他路径。处理多路径的更好方法是结合使用 PermitOnly 和 Deny。在上面的示例中,可以 PermitOnly \\server\share,然后 Deny \\server\share\file,从而完全消除所有替换路径。有关此主题以及如何结合使用 PermitOnly 和 Deny 的更多信息,请参见 使用 Deny 方法 中的“使用拒绝的规范化问题”。
提示
\\server\share\bogusfolder\..\file 形式的路径被安全系统转化为规范化的形式 \\server\share\file,这样只需要 Deny 规范化路径 \\server\share\file 即可,而不必考虑可用于指定同一路径的其他表示方法。点运算符 (.) 可以单独显示,多个一起显示,也可以与尾随的空白字符结合显示。如果空白跟在点运算符之后,则忽略这些空白。单点(例如在 C:\temp\test\.\test.txt 地址中)将被忽略,得到的地址为 C:\temp\test\test.txt。多点运算符将视为“..”,意味着跳过紧接着的上一级目录。例如,地址 C:\temp\test\....\test.txt 得到的路径为 C:\temp\test.txt。
提示
Deny 对于 Windows NTFS 文件系统最为有效。同 FAT32 相比,NTFS 的安全性有很大程度的提高。有关 NTFS 的详细信息,请参见 Windows 文档。
示例
下列示例阐释使用 FileIOPermission 的代码。在下列两行代码之后,对象 f
表示读取客户端计算机的本地磁盘上的所有文件的权限。
Dim f As New FileIOPermission(PermissionState.None)
f.AllLocalFiles = FileIOPermissionAccess.Read
FileIOPermission f = new FileIOPermission(PermissionState.None);
f.AllLocalFiles = FileIOPermissionAccess.Read;
FileIOPermission^ f = gcnew FileIOPermission( PermissionState::None );
f->AllLocalFiles = FileIOPermissionAccess::Read;
FileIOPermission f = new FileIOPermission(PermissionState.None);
f.set_AllLocalFiles(FileIOPermissionAccess.Read);
在下列两行代码之后,对象 f2
表示读取 C:\test_r 和读写 C:\example\out.txt 的权限。Read 和 Write 表示如上所述的文件/文件夹权限。
Dim f2 As New FileIOPermission(FileIOPermissionAccess.Read, "C:\test_r")
f2.AddPathList(FileIOPermissionAccess.Write Or _
FileIOPermissionAccess.Read, "C:\example\out.txt")
FileIOPermission f2 = new FileIOPermission(FileIOPermissionAccess.Read, "C:\\test_r");
f2.AddPathList(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, "C:\\example\\out.txt");
FileIOPermission^ f2 = gcnew FileIOPermission( FileIOPermissionAccess::Read,"C:\\test_r" );
f2->AddPathList( (FileIOPermissionAccess) (FileIOPermissionAccess::Write | FileIOPermissionAccess::Read), "C:\\example\\out.txt" );
FileIOPermission f2 =
new FileIOPermission(FileIOPermissionAccess.Read, "C:\\test_r");
f2.AddPathList(FileIOPermissionAccess.Write |
FileIOPermissionAccess.Read, "C:\\example\\out.txt");
下面的示例阐释一些 FileIOPermission 成员。
Imports System
Imports System.Security
Imports System.Security.Permissions
Imports System.Collections
Imports Microsoft.VisualBasic
<Assembly: CLSCompliant(True)>
Public Class FileIOPermissionDemo
' IsSubsetOf determines whether the current permission is a subset of the specified permission.
' This method compares various FileIOPermission paths with FileIOPermissionAccess set to AllAccess.
Private Function IsSubsetOfDemo() As Boolean
Dim returnValue As Boolean = True
Dim fileIO1 As String = ""
Dim fileIO2 As String = ""
Dim fileIOPerm1, fileIOPerm2 As FileIOPermission
Dim fileIOGen1 As New FileIOGenerator()
Dim fileIOGen2 As New FileIOGenerator()
fileIOGen1.ResetIndex()
While fileIOGen1.CreateFilePath(fileIO1)
If fileIO1 = "" Then
fileIOPerm1 = New FileIOPermission(PermissionState.None)
Else
fileIOPerm1 = New FileIOPermission(FileIOPermissionAccess.AllAccess, fileIO1)
End If
Console.WriteLine("**********************************************************" & ControlChars.Lf)
fileIOGen2.ResetIndex()
While fileIOGen2.CreateFilePath(fileIO2)
If fileIO2 = "" Then
fileIOPerm2 = New FileIOPermission(PermissionState.None)
Else
fileIOPerm2 = New FileIOPermission(FileIOPermissionAccess.AllAccess, fileIO2)
End If
Dim firstPermission As String = IIf(fileIO1 = "" Or fileIO1 Is Nothing, "null", fileIO1)
Dim secondPermission As String = IIf(fileIO2 = "" Or fileIO2 Is Nothing, "null", fileIO2)
If fileIOPerm2 Is Nothing Then
GoTo ContinueWhile2
End If
Try
If fileIOPerm1.IsSubsetOf(fileIOPerm2) Then
Console.WriteLine((firstPermission & " is a subset of " & secondPermission & ControlChars.Lf))
Else
Console.WriteLine((firstPermission & " is not a subset of " & secondPermission & ControlChars.Lf))
End If
Catch e As Exception
Console.WriteLine(IIf("An exception was thrown for subset :" & fileIO1 = "", "null", IIf(fileIO1 & ControlChars.Lf & fileIO2 = "", "null", fileIO2 & ControlChars.Lf & e.ToString())))
End Try
ContinueWhile2:
End While
ContinueWhile1:
End While
Return returnValue
End Function 'IsSubsetOfDemo
' Union creates a new permission that is the union of the current permission and the specified permission.
Private Function UnionDemo() As Boolean
Dim returnValue As Boolean = True
Dim fileIO1 As String = ""
Dim fileIO2 As String = ""
Dim fileIOPerm1, fileIOPerm2 As FileIOPermission
Dim fileIOPerm3 As IPermission
Dim fileIOGen1 As New FileIOGenerator()
Dim fileIOGen2 As New FileIOGenerator()
fileIOGen1.ResetIndex()
While fileIOGen1.CreateFilePath(fileIO1)
If fileIO1 = "" Then
fileIOPerm1 = New FileIOPermission(PermissionState.None)
Else
fileIOPerm1 = New FileIOPermission(FileIOPermissionAccess.Read, fileIO1)
End If
Console.WriteLine("**********************************************************" & ControlChars.Lf)
fileIOGen2.ResetIndex()
While fileIOGen2.CreateFilePath(fileIO2)
Try
If fileIO2 = "" Then
fileIOPerm2 = New FileIOPermission(PermissionState.None)
Else
fileIOPerm2 = New FileIOPermission(FileIOPermissionAccess.Read, fileIO2)
End If
Dim firstPermission As String = IIf(fileIO1 = "" Or fileIO1 Is Nothing, "null", fileIO1)
Dim secondPermission As String = IIf(fileIO2 = "" Or fileIO2 Is Nothing, "null", fileIO2)
fileIOPerm3 = CType(fileIOPerm1.Union(fileIOPerm2), FileIOPermission)
fileIOPerm3 = fileIOPerm1.Union(fileIOPerm2)
If fileIOPerm3 Is Nothing Then
Console.WriteLine(("The union of " & firstPermission & " and " & secondPermission & " is null."))
Else
Console.WriteLine(("The union of " & firstPermission & " and " & secondPermission & " = " & ControlChars.Lf & ControlChars.Tab & CType(fileIOPerm3, FileIOPermission).GetPathList(FileIOPermissionAccess.Read)(0)))
End If
Catch e As Exception
Console.WriteLine(("An exception was thrown for union " & e.ToString()))
returnValue = False
End Try
ContinueWhile2:
End While
ContinueWhile1:
End While
Return returnValue
End Function 'UnionDemo
' Intersect creates and returns a new permission that is the intersection of the current
' permission and the permission specified.
Private Function IntersectDemo() As Boolean
Dim returnValue As Boolean = True
Dim fileIO1 As String = ""
Dim fileIO2 As String = ""
Dim fileIOPerm1, fileIOPerm2, fileIOPerm3 As FileIOPermission
Dim fileIOGen1 As New FileIOGenerator()
Dim fileIOGen2 As New FileIOGenerator()
fileIOGen1.ResetIndex()
While fileIOGen1.CreateFilePath(fileIO1)
If fileIO1 = "" Then
fileIOPerm1 = New FileIOPermission(PermissionState.None)
Else
fileIOPerm1 = New FileIOPermission(FileIOPermissionAccess.Read, fileIO1)
End If
Console.WriteLine("**********************************************************" & ControlChars.Lf)
fileIOGen2.ResetIndex()
While fileIOGen2.CreateFilePath(fileIO2)
If fileIO2 = "" Then
fileIOPerm2 = New FileIOPermission(PermissionState.None)
Else
fileIOPerm2 = New FileIOPermission(FileIOPermissionAccess.Read, fileIO2)
End If
Dim firstPermission As String = IIf(fileIO1 = "" Or fileIO1 Is Nothing, "null", fileIO1)
Dim secondPermission As String = IIf(fileIO2 = "" Or fileIO2 Is Nothing, "null", fileIO2)
Try
fileIOPerm3 = CType(fileIOPerm1.Intersect(fileIOPerm2), FileIOPermission)
If Not (fileIOPerm3 Is Nothing) AndAlso Not (fileIOPerm3.GetPathList(FileIOPermissionAccess.Read) Is Nothing) Then
Console.WriteLine(("The intersection of " & firstPermission & " and " & ControlChars.Lf & ControlChars.Tab & secondPermission & " = " & ControlChars.Lf & ControlChars.Tab & CType(fileIOPerm3, FileIOPermission).GetPathList(FileIOPermissionAccess.Read)(0)))
Else
Console.WriteLine(("The intersection of " & firstPermission & " and " & secondPermission & " is null."))
End If
Catch e As Exception
Console.WriteLine(("An exception was thrown for intersection " & e.ToString()))
returnValue = False
End Try
ContinueWhile2:
End While
ContinueWhile1:
End While
Return returnValue
End Function 'IntersectDemo
'Copy creates and returns an identical copy of the current permission.
Private Function CopyDemo() As Boolean
Dim returnValue As Boolean = True
Dim fileIO1 As String = ""
Dim fileIOPerm1, fileIOPerm2 As FileIOPermission
Dim fileIOGen1 As New FileIOGenerator()
Dim fileIOGen2 As New FileIOGenerator()
fileIOGen1.ResetIndex()
While fileIOGen1.CreateFilePath(fileIO1)
If fileIO1 = "" Then
fileIOPerm1 = New FileIOPermission(PermissionState.None)
Else
fileIOPerm1 = New FileIOPermission(FileIOPermissionAccess.Read, fileIO1)
End If
Console.WriteLine("**********************************************************" & ControlChars.Lf)
fileIOGen2.ResetIndex()
Try
fileIOPerm2 = CType(fileIOPerm1.Copy(), FileIOPermission)
If Not (fileIOPerm2 Is Nothing) Then
Console.WriteLine(("Result of copy = " & fileIOPerm2.ToString() & ControlChars.Lf))
Else
Console.WriteLine("Result of copy is null. " & ControlChars.Lf)
End If
Catch e As Exception
If (True.ToString()) Then
If fileIO1 = "" Then
Console.WriteLine("The target FileIOPermission is empty, copy failed.")
Else
Console.WriteLine(e.ToString())
End If
End If
GoTo ContinueWhile1
End Try
ContinueWhile1:
End While
Return returnValue
End Function 'CopyDemo
' ToXml creates an XML encoding of the permission and its current state;
' FromXml reconstructs a permission with the specified state from the XML encoding.
Private Function ToFromXmlDemo() As Boolean
Dim returnValue As Boolean = True
Dim fileIO1 As String = ""
Dim fileIOPerm1, fileIOPerm2 As FileIOPermission
Dim fileIOGen1 As New FileIOGenerator()
Dim fileIOGen2 As New FileIOGenerator()
fileIOGen1.ResetIndex()
While fileIOGen1.CreateFilePath(fileIO1)
If fileIO1 = "" Then
fileIOPerm1 = New FileIOPermission(PermissionState.None)
Else
fileIOPerm1 = New FileIOPermission(FileIOPermissionAccess.Read, fileIO1)
End If
Console.WriteLine("********************************************************" & ControlChars.Lf)
fileIOGen2.ResetIndex()
Try
fileIOPerm2 = New FileIOPermission(PermissionState.None)
fileIOPerm2.FromXml(fileIOPerm1.ToXml())
Console.WriteLine(("Result of ToFromXml = " & fileIOPerm2.ToString() & ControlChars.Lf))
Catch e As Exception
Console.WriteLine(("ToFromXml failed :" & fileIOPerm1.ToString() & e.ToString()))
GoTo ContinueWhile1
End Try
ContinueWhile1:
End While
Return returnValue
End Function 'ToFromXmlDemo
' AddPathList adds access for the specified files and directories to the existing state of the permission.
' SetPathList sets the specified access to the specified files and directories, replacing the existing state
' of the permission.
' GetPathList gets all files and directories that have the specified FileIOPermissionAccess.
Private Function SetGetPathListDemo() As Boolean
Try
Console.WriteLine("********************************************************" & ControlChars.Lf)
Dim fileIOPerm1 As FileIOPermission
Console.WriteLine("Creating a FileIOPermission with AllAccess rights for 'C:\Examples\Test\TestFile.txt")
fileIOPerm1 = New FileIOPermission(FileIOPermissionAccess.AllAccess, "C:\Examples\Test\TestFile.txt")
Console.WriteLine("Adding 'C:\Temp' to the write access list, and " & ControlChars.Lf & " 'C:\Examples\Test' to read access.")
fileIOPerm1.AddPathList(FileIOPermissionAccess.Write, "C:\Temp")
fileIOPerm1.AddPathList(FileIOPermissionAccess.Read, "C:\Examples\Test")
Dim paths As String() = fileIOPerm1.GetPathList(FileIOPermissionAccess.Read)
Console.WriteLine("Read access before SetPathList = ")
Dim path As String
For Each path In paths
Console.WriteLine((ControlChars.Tab & path))
Next path
Console.WriteLine("Setting the read access list to " & ControlChars.Lf & "'C:\Temp'")
fileIOPerm1.SetPathList(FileIOPermissionAccess.Read, "C:\Temp")
paths = fileIOPerm1.GetPathList(FileIOPermissionAccess.Read)
Console.WriteLine("Read access list after SetPathList = ")
For Each path In paths
Console.WriteLine((ControlChars.Tab & path))
Next path
paths = fileIOPerm1.GetPathList(FileIOPermissionAccess.Write)
Console.WriteLine("Write access list after SetPathList = ")
For Each path In paths
Console.WriteLine((ControlChars.Tab & path))
Next path
Dim pathList() As String
pathList = fileIOPerm1.GetPathList(FileIOPermissionAccess.AllAccess)
Catch e As ArgumentException
' FileIOPermissionAccess.AllAccess can not be used as a parameter for GetPathList.
Console.WriteLine(("An ArgumentException occurred as a result of using AllAccess. " & "This property cannot be used as a parameter in GetPathList " & "because it represents more than one type of file variable access. : " & ControlChars.Lf & e.ToString()))
End Try
Return True
End Function 'SetGetPathListDemo
' The AllFiles property gets or sets the permitted access to all files.
' The AllLocalFiles property gets or sets the permitted access to all local files.
Private Function AllFilesDemo() As Boolean
Try
Console.WriteLine("********************************************************" & ControlChars.Lf)
Dim fileIOPerm1 As FileIOPermission
Console.WriteLine("Creating a FileIOPermission and adding read access for all files")
fileIOPerm1 = New FileIOPermission(FileIOPermissionAccess.AllAccess, "C:\Examples\Test\TestFile.txt")
fileIOPerm1.AllFiles = FileIOPermissionAccess.Read
Console.WriteLine("AllFiles access = " & fileIOPerm1.AllFiles.ToString())
Console.WriteLine("Adding AllAccess rights for local files.")
fileIOPerm1.AllLocalFiles = FileIOPermissionAccess.AllAccess
Console.WriteLine("AllLocalFiles access = " & fileIOPerm1.AllLocalFiles.ToString())
Catch e As ArgumentException
Console.WriteLine(e.ToString())
Return False
End Try
Return True
End Function 'AllFilesDemo
' Invoke all demos.
Public Function RunDemo() As Boolean
Dim ret As Boolean = True
Dim retTmp As Boolean
' Call the IsSubsetOfPath demo.
retTmp = IsSubsetOfDemo()
If retTmp Then
Console.Out.WriteLine("IsSubsetOf demo completed successfully.")
Else
Console.Out.WriteLine("IsSubsetOf demo failed.")
End If
ret = retTmp AndAlso ret
' Call the Union demo.
retTmp = UnionDemo()
If retTmp Then
Console.Out.WriteLine("Union demo completed successfully.")
Else
Console.Out.WriteLine("Union demo failed.")
End If
ret = retTmp AndAlso ret
' Call the Intersect demo.
retTmp = IntersectDemo()
If retTmp Then
Console.Out.WriteLine("Intersect demo completed successfully.")
Else
Console.Out.WriteLine("Intersect demo failed.")
End If
ret = retTmp AndAlso ret
' Call the Copy demo.
retTmp = CopyDemo()
If retTmp Then
Console.Out.WriteLine("Copy demo completed successfully.")
Else
Console.Out.WriteLine("Copy demo failed.")
End If
ret = retTmp AndAlso ret
' Call the ToFromXml demo.
retTmp = ToFromXmlDemo()
If retTmp Then
Console.Out.WriteLine("ToFromXml demo completed successfully.")
Else
Console.Out.WriteLine("ToFromXml demo failed.")
End If
ret = retTmp AndAlso ret
' Call the SetGetPathList demo.
retTmp = SetGetPathListDemo()
If retTmp Then
Console.Out.WriteLine("SetGetPathList demo completed successfully.")
Else
Console.Out.WriteLine("SetGetPathList demo failed.")
End If
ret = retTmp AndAlso ret
' Call the AllFiles demo.
retTmp = AllFilesDemo()
If retTmp Then
Console.Out.WriteLine("AllFiles demo completed successfully.")
Else
Console.Out.WriteLine("AllFiles demo failed.")
End If
ret = retTmp AndAlso ret
Return ret
End Function 'RunDemo
' Test harness.
Public Overloads Shared Sub Main(ByVal args() As [String])
Try
Dim democase As New FileIOPermissionDemo()
Dim ret As Boolean = democase.RunDemo()
If ret Then
Console.Out.WriteLine("FileIOPermission demo completed successfully.")
Console.Out.WriteLine("Press the Enter key to exit.")
Dim consoleInput As String = Console.ReadLine()
System.Environment.ExitCode = 100
Else
Console.Out.WriteLine("FileIOPermission demo failed.")
Console.Out.WriteLine("Press the Enter key to exit.")
Dim consoleInput As String = Console.ReadLine()
System.Environment.ExitCode = 101
End If
Catch e As Exception
Console.Out.WriteLine("FileIOPermission demo failed")
Console.WriteLine(e.ToString())
Console.Out.WriteLine("Press the Enter key to exit.")
Dim consoleInput As String = Console.ReadLine()
System.Environment.ExitCode = 101
End Try
End Sub 'Main
End Class 'FileIOPermissionDemo
' This class generates FileIOPermission objects.
Friend Class FileIOGenerator
Private myFile As String() = {"C:\Examples\Test\TestFile.txt", "C:\Examples\Test\", "C:\Examples\Test\..", "C:\Temp"}
Private myAccess As FileIOPermissionAccess() = {FileIOPermissionAccess.AllAccess, FileIOPermissionAccess.Append, FileIOPermissionAccess.NoAccess, FileIOPermissionAccess.PathDiscovery, FileIOPermissionAccess.Read, FileIOPermissionAccess.Write}
Private fileIndex As Integer = 0
Public Sub New()
ResetIndex()
End Sub 'New
Public Sub ResetIndex()
fileIndex = 0
End Sub 'ResetIndex
' Create a file path.
Public Function CreateFilePath(ByRef file As String) As Boolean
If fileIndex = myFile.Length Then
file = ""
fileIndex &= 1
Return True
End If
If fileIndex > myFile.Length Then
file = ""
Return False
End If
file = myFile(fileIndex)
fileIndex = fileIndex + 1
Try
Return True
Catch e As Exception
Console.WriteLine(("Cannot create FileIOPermission: " & file & " " & e.ToString()))
file = ""
Return True
End Try
End Function
End Class
using System;
using System.Security;
using System.Security.Permissions;
using System.Collections;
[assembly: CLSCompliant(true)]
public class FileIOPermissionDemo
{
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
// This method compares various FileIOPermission paths with FileIOPermissionAccess set to AllAccess.
private bool IsSubsetOfDemo()
{
bool returnValue = true;
string fileIO1, fileIO2;
FileIOPermission fileIOPerm1, fileIOPerm2;
FileIOGenerator fileIOGen1 = new FileIOGenerator();
FileIOGenerator fileIOGen2 = new FileIOGenerator();
fileIOGen1.ResetIndex();
while (fileIOGen1.CreateFilePath(out fileIO1 ))
{
if(fileIO1 == "")
fileIOPerm1 = new FileIOPermission(PermissionState.None);
else
fileIOPerm1 = new FileIOPermission(FileIOPermissionAccess.AllAccess, fileIO1);
Console.WriteLine("**********************************************************\n");
fileIOGen2.ResetIndex();
while (fileIOGen2.CreateFilePath(out fileIO2))
{
if (fileIO2 == "")
fileIOPerm2 = new FileIOPermission(PermissionState.None);
else
fileIOPerm2 = new FileIOPermission(FileIOPermissionAccess.AllAccess, fileIO2);
string firstPermission = fileIO1 == "" | fileIO1 == null ? "null" : fileIO1;
string secondPermission = fileIO2 == "" | fileIO2 == null ? "null" : fileIO2;
if (fileIOPerm2 == null) continue;
try
{
if (fileIOPerm1.IsSubsetOf(fileIOPerm2))
{
Console.WriteLine(firstPermission + " is a subset of " + secondPermission + "\n");
}
else
{
Console.WriteLine(firstPermission + " is not a subset of " + secondPermission + "\n");
}
}
catch (Exception e)
{
Console.WriteLine("An exception was thrown for subset :" + fileIO1 == "" ? "null" : fileIO1 + "\n" +
fileIO2 == "" ? "null" : fileIO2 + "\n" + e);
}
}
}
return returnValue;
}
// Union creates a new permission that is the union of the current permission and the specified permission.
private bool UnionDemo()
{
bool returnValue = true;
string fileIO1, fileIO2;
FileIOPermission fileIOPerm1, fileIOPerm2;
IPermission fileIOPerm3;
FileIOGenerator fileIOGen1 = new FileIOGenerator();
FileIOGenerator fileIOGen2 = new FileIOGenerator();
fileIOGen1.ResetIndex();
while (fileIOGen1.CreateFilePath( out fileIO1 ))
{
if (fileIO1 == "")
fileIOPerm1 = new FileIOPermission(PermissionState.None);
else
fileIOPerm1 = new FileIOPermission(FileIOPermissionAccess.Read, fileIO1);
if (fileIO1 == null) continue;
Console.WriteLine("**********************************************************\n");
fileIOGen2.ResetIndex();
while (fileIOGen2.CreateFilePath( out fileIO2 ))
{
if (fileIO2 == "")
fileIOPerm2 = new FileIOPermission(PermissionState.None);
else
fileIOPerm2 = new FileIOPermission(FileIOPermissionAccess.Read, fileIO2);
try
{
string firstPermission = fileIO1 == "" | fileIO1 == null ? "null" : fileIO1;
string secondPermission = fileIO2 == "" | fileIO2 == null ? "null" : fileIO2;
fileIOPerm3 = (FileIOPermission)fileIOPerm1.Union(fileIOPerm2);
fileIOPerm3 = fileIOPerm1.Union(fileIOPerm2);
if (fileIOPerm3 == null)
{
Console.WriteLine("The union of " + firstPermission + " and " + secondPermission + " is null.");
}
else
{
Console.WriteLine("The union of " + firstPermission + " and " + secondPermission +
" = \n\t" + ((FileIOPermission)fileIOPerm3).GetPathList(FileIOPermissionAccess.Read)[0]);
}
}
catch (Exception e)
{
Console.WriteLine("An exception was thrown for union " + e);
returnValue = false;
}
}
}
return returnValue;
}
// Intersect creates and returns a new permission that is the intersection of the current
// permission and the permission specified.
private bool IntersectDemo()
{
bool returnValue = true;
string fileIO1, fileIO2;
FileIOPermission fileIOPerm1, fileIOPerm2, fileIOPerm3;
FileIOGenerator fileIOGen1 = new FileIOGenerator();
FileIOGenerator fileIOGen2 = new FileIOGenerator();
fileIOGen1.ResetIndex();
while (fileIOGen1.CreateFilePath(out fileIO1 ))
{
if (fileIO1 == "")
fileIOPerm1 = new FileIOPermission(PermissionState.None);
else
fileIOPerm1 = new FileIOPermission(FileIOPermissionAccess.Read, fileIO1);
Console.WriteLine("**********************************************************\n");
fileIOGen2.ResetIndex();
while (fileIOGen2.CreateFilePath( out fileIO2 ))
{
if (fileIO2 == "")
fileIOPerm2 = new FileIOPermission(PermissionState.None);
else
fileIOPerm2 = new FileIOPermission(FileIOPermissionAccess.Read, fileIO2);
string firstPermission = fileIO1 == "" | fileIO1 == null ? "null" : fileIO1;
string secondPermission = fileIO2 == "" | fileIO2 == null ? "null" : fileIO2;
try
{
fileIOPerm3 = (FileIOPermission)fileIOPerm1.Intersect(fileIOPerm2);
if (fileIOPerm3 != null && fileIOPerm3.GetPathList(FileIOPermissionAccess.Read) != null)
{
Console.WriteLine("The intersection of " + firstPermission + " and \n\t" + secondPermission +
" = \n\t" + ((FileIOPermission)fileIOPerm3).GetPathList(FileIOPermissionAccess.Read)[0]);
}
else
{
Console.WriteLine("The intersection of " + firstPermission + " and " + secondPermission + " is null.");
}
}
catch (Exception e)
{
Console.WriteLine("An exception was thrown for intersection " + e);
returnValue = false;
}
}
}
return returnValue;
}
//Copy creates and returns an identical copy of the current permission.
private bool CopyDemo()
{
bool returnValue = true;
string fileIO1;
FileIOPermission fileIOPerm1, fileIOPerm2;
FileIOGenerator fileIOGen1 = new FileIOGenerator();
FileIOGenerator fileIOGen2 = new FileIOGenerator();
fileIOGen1.ResetIndex();
while (fileIOGen1.CreateFilePath( out fileIO1 ))
{
if (fileIO1 == "")
fileIOPerm1 = new FileIOPermission(PermissionState.None);
else
fileIOPerm1 = new FileIOPermission(FileIOPermissionAccess.Read, fileIO1);
Console.WriteLine("**********************************************************\n");
fileIOGen2.ResetIndex();
try
{
fileIOPerm2 = (FileIOPermission)fileIOPerm1.Copy();
if (fileIOPerm2 != null)
{
Console.WriteLine("Result of copy = " + fileIOPerm2.ToString() + "\n");
}
else
{
Console.WriteLine("Result of copy is null. \n");
}
}
catch (Exception e)
{
{
if (fileIO1 == "")
{
Console.WriteLine("The target FileIOPermission is empty, copy failed.");
}
else
Console.WriteLine(e);
}
continue;
}
}
return returnValue;
}
// ToXml creates an XML encoding of the permission and its current state;
// FromXml reconstructs a permission with the specified state from the XML encoding.
private bool ToFromXmlDemo()
{
bool returnValue = true;
string fileIO1;
FileIOPermission fileIOPerm1, fileIOPerm2;
FileIOGenerator fileIOGen1 = new FileIOGenerator();
FileIOGenerator fileIOGen2 = new FileIOGenerator();
fileIOGen1.ResetIndex();
while (fileIOGen1.CreateFilePath( out fileIO1 ))
{
if (fileIO1 == "")
fileIOPerm1 = new FileIOPermission(PermissionState.None);
else
fileIOPerm1 = new FileIOPermission(FileIOPermissionAccess.Read, fileIO1);
Console.WriteLine("********************************************************\n");
fileIOGen2.ResetIndex();
try
{
fileIOPerm2 = new FileIOPermission(PermissionState.None);
fileIOPerm2.FromXml(fileIOPerm1.ToXml());
Console.WriteLine("Result of ToFromXml = " + fileIOPerm2.ToString() + "\n");
}
catch (Exception e)
{
Console.WriteLine("ToFromXml failed :" + fileIOPerm1.ToString() + e);
continue;
}
}
return returnValue;
}
// AddPathList adds access for the specified files and directories to the existing state of the permission.
// SetPathList sets the specified access to the specified files and directories, replacing the existing state
// of the permission.
// GetPathList gets all files and directories that have the specified FileIOPermissionAccess.
private bool SetGetPathListDemo()
{
try
{
Console.WriteLine("********************************************************\n");
FileIOPermission fileIOPerm1;
Console.WriteLine("Creating a FileIOPermission with AllAccess rights for 'C:\\Examples\\Test\\TestFile.txt");
fileIOPerm1 = new FileIOPermission(FileIOPermissionAccess.AllAccess, "C:\\Examples\\Test\\TestFile.txt");
Console.WriteLine("Adding 'C:\\Temp' to the write access list, and \n 'C:\\Examples\\Test' to read access.");
fileIOPerm1.AddPathList(FileIOPermissionAccess.Write, "C:\\Temp");
fileIOPerm1.AddPathList(FileIOPermissionAccess.Read, "C:\\Examples\\Test");
string[] paths = fileIOPerm1.GetPathList(FileIOPermissionAccess.Read);
Console.WriteLine("Read access before SetPathList = ");
foreach (string path in paths)
{
Console.WriteLine("\t" + path);
}
Console.WriteLine("Setting the read access list to \n'C:\\Temp'");
fileIOPerm1.SetPathList(FileIOPermissionAccess.Read, "C:\\Temp");
paths = fileIOPerm1.GetPathList(FileIOPermissionAccess.Read);
Console.WriteLine("Read access list after SetPathList = ");
foreach (string path in paths)
{
Console.WriteLine("\t" + path);
}
paths = fileIOPerm1.GetPathList(FileIOPermissionAccess.Write);
Console.WriteLine("Write access list after SetPathList = ");
foreach (string path in paths)
{
Console.WriteLine("\t" + path);
}
Console.WriteLine("Write access = \n" +
fileIOPerm1.GetPathList(FileIOPermissionAccess.AllAccess));
}
catch (ArgumentException e)
{
// FileIOPermissionAccess.AllAccess can not be used as a parameter for GetPathList.
Console.WriteLine("An ArgumentException occurred as a result of using AllAccess. "
+ "This property cannot be used as a parameter in GetPathList "
+ "because it represents more than one type of file variable access. : \n" + e);
}
return true;
}
// The AllFiles property gets or sets the permitted access to all files.
// The AllLocalFiles property gets or sets the permitted access to all local files.
private bool AllFilesDemo()
{
try
{
Console.WriteLine("********************************************************\n");
FileIOPermission fileIOPerm1;
Console.WriteLine("Creating a FileIOPermission and adding read access for all files");
fileIOPerm1 = new FileIOPermission(FileIOPermissionAccess.AllAccess, "C:\\Examples\\Test\\TestFile.txt");
fileIOPerm1.AllFiles = FileIOPermissionAccess.Read;
Console.WriteLine("AllFiles access = " + fileIOPerm1.AllFiles);
Console.WriteLine("Adding AllAccess rights for local files.");
fileIOPerm1.AllLocalFiles = FileIOPermissionAccess.AllAccess;
Console.WriteLine("AllLocalFiles access = " + fileIOPerm1.AllLocalFiles);
}
catch (ArgumentException e)
{
Console.WriteLine(e);
return false;
}
return true;
}
// Invoke all demos.
public bool RunDemo()
{
bool ret = true;
bool retTmp;
// Call the IsSubsetOfPath demo.
if (retTmp = IsSubsetOfDemo()) Console.Out.WriteLine("IsSubsetOf demo completed successfully.");
else Console.Out.WriteLine("IsSubsetOf demo failed.");
ret = retTmp && ret;
// Call the Union demo.
if (retTmp = UnionDemo()) Console.Out.WriteLine("Union demo completed successfully.");
else Console.Out.WriteLine("Union demo failed.");
ret = retTmp && ret;
// Call the Intersect demo.
if (retTmp = IntersectDemo()) Console.Out.WriteLine("Intersect demo completed successfully.");
else Console.Out.WriteLine("Intersect demo failed.");
ret = retTmp && ret;
// Call the Copy demo.
if (retTmp = CopyDemo()) Console.Out.WriteLine("Copy demo completed successfully.");
else Console.Out.WriteLine("Copy demo failed.");
ret = retTmp && ret;
// Call the ToFromXml demo.
if (retTmp = ToFromXmlDemo()) Console.Out.WriteLine("ToFromXml demo completed successfully.");
else Console.Out.WriteLine("ToFromXml demo failed.");
ret = retTmp && ret;
// Call the SetGetPathList demo.
if (retTmp = SetGetPathListDemo()) Console.Out.WriteLine("SetGetPathList demo completed successfully.");
else Console.Out.WriteLine("SetGetPathList demo failed.");
ret = retTmp && ret;
// Call the AllFiles demo.
if (retTmp = AllFilesDemo()) Console.Out.WriteLine("AllFiles demo completed successfully.");
else Console.Out.WriteLine("AllFiles demo failed.");
ret = retTmp && ret;
return (ret);
}
// Test harness.
public static void Main(String[] args)
{
try
{
FileIOPermissionDemo democase = new FileIOPermissionDemo();
bool ret = democase.RunDemo();
if (ret)
{
Console.Out.WriteLine("FileIOPermission demo completed successfully.");
Console.Out.WriteLine("Press the Enter key to exit.");
string consoleInput = Console.ReadLine();
System.Environment.ExitCode = 100;
}
else
{
Console.Out.WriteLine("FileIOPermission demo failed.");
Console.Out.WriteLine("Press the Enter key to exit.");
string consoleInput = Console.ReadLine();
System.Environment.ExitCode = 101;
}
}
catch (Exception e)
{
Console.Out.WriteLine("FileIOPermission demo failed");
Console.WriteLine(e.ToString());
Console.Out.WriteLine("Press the Enter key to exit.");
string consoleInput = Console.ReadLine();
System.Environment.ExitCode = 101;
}
}
}
// This class generates FileIOPermission objects.
internal class FileIOGenerator
{
private string[] myFile =
{
"C:\\Examples\\Test\\TestFile.txt",
"C:\\Examples\\Test\\",
"C:\\Examples\\Test\\..",
"C:\\Temp"
};
private FileIOPermissionAccess[] myAccess =
{
FileIOPermissionAccess.AllAccess,
FileIOPermissionAccess.Append,
FileIOPermissionAccess.NoAccess,
FileIOPermissionAccess.PathDiscovery,
FileIOPermissionAccess.Read,
FileIOPermissionAccess.Write
};
private int fileIndex = 0;
public FileIOGenerator()
{
ResetIndex();
}
public void ResetIndex()
{
fileIndex = 0;
}
// Create a file path string.
public bool CreateFilePath( out string file )
{
if (fileIndex == myFile.Length)
{
file = "";
fileIndex++;
return true;
}
if (fileIndex > myFile.Length)
{
file = "";
return false;
}
file = myFile[fileIndex++];
try
{
return true;
}
catch (Exception e)
{
Console.WriteLine("Cannot create FileIOPermission: " + file + " " + e);
file = "";
return true;
}
}
}
using namespace System::Runtime::InteropServices;
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::Collections;
// This class generates FileIOPermission objects.
[assembly:CLSCompliant(true)];
private ref class FileIOGenerator
{
private:
array<String^>^myFile;
array<FileIOPermissionAccess>^myAccess;
int fileIndex;
public:
FileIOGenerator()
{
array<String^>^tempFile = {"C:\\Examples\\Test\\TestFile.txt","C:\\Examples\\Test\\","C:\\Examples\\Test\\..","C:\\Temp"};
myFile = tempFile;
array<FileIOPermissionAccess>^ tempAccess = {FileIOPermissionAccess::AllAccess,FileIOPermissionAccess::Append,FileIOPermissionAccess::NoAccess,FileIOPermissionAccess::PathDiscovery,FileIOPermissionAccess::Read,FileIOPermissionAccess::Write};
myAccess = tempAccess;
ResetIndex();
}
void ResetIndex()
{
fileIndex = 0;
}
// Create a file path.
bool CreateFilePath( [Out]interior_ptr<String^> file )
{
if ( fileIndex == myFile->Length )
{
*file = "";
fileIndex++;
return true;
}
if ( fileIndex > myFile->Length )
{
*file = "";
return false;
}
*file = myFile[ fileIndex++ ];
try
{
return true;
}
catch ( Exception^ e )
{
Console::WriteLine( "Cannot create FileIOPermission: {0} {1}", *file, e );
*file = "";
return true;
}
}
};
public ref class FileIOPermissionDemo
{
private:
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
// This method compares various FileIOPermission paths with FileIOPermissionAccess set to AllAccess.
bool IsSubsetOfDemo()
{
bool returnValue = true;
String^ fileIO1;
String^ fileIO2;
FileIOPermission^ fileIOPerm1;
FileIOPermission^ fileIOPerm2;
FileIOGenerator^ fileIOGen1 = gcnew FileIOGenerator;
FileIOGenerator^ fileIOGen2 = gcnew FileIOGenerator;
fileIOGen1->ResetIndex();
while ( fileIOGen1->CreateFilePath( &fileIO1 ) )
{
if (fileIO1 == "")
fileIOPerm1 = gcnew FileIOPermission(PermissionState::None);
else
fileIOPerm1 = gcnew FileIOPermission(FileIOPermissionAccess::AllAccess, fileIO1);
Console::WriteLine( "**********************************************************\n" );
fileIOGen2->ResetIndex();
while ( fileIOGen2->CreateFilePath( &fileIO2 ) )
{
if (fileIO2 == "")
fileIOPerm2 = gcnew FileIOPermission(PermissionState::None);
else
fileIOPerm2 = gcnew FileIOPermission(FileIOPermissionAccess::AllAccess, fileIO2);
String^ firstPermission = fileIO1 == "" || fileIO1 == nullptr ? "null" : fileIO1;
String^ secondPermission = fileIO2 == "" || fileIO2 == nullptr ? "null" : fileIO2;
if ( fileIOPerm2 == nullptr )
continue;
try
{
if ( fileIOPerm1->IsSubsetOf( fileIOPerm2 ) )
{
Console::WriteLine( "{0} is a subset of {1}\n", firstPermission, secondPermission );
}
else
{
Console::WriteLine( "{0} is not a subset of {1}\n", firstPermission, secondPermission );
}
}
catch ( Exception^ e )
{
Console::WriteLine( "An exception was thrown for subset :{0}\n{1}\n{2}", (fileIO1->Equals( "" ) ? "null" : fileIO1), (fileIO2->Equals( "" ) ? "null" : fileIO2), e );
}
}
}
return returnValue;
}
// Union creates a new permission that is the union of the current permission and the specified permission.
bool UnionDemo()
{
bool returnValue = true;
String^ fileIO1;
String^ fileIO2;
FileIOPermission^ fileIOPerm1;
FileIOPermission^ fileIOPerm2;
IPermission^ fileIOPerm3;
FileIOGenerator^ fileIOGen1 = gcnew FileIOGenerator;
FileIOGenerator^ fileIOGen2 = gcnew FileIOGenerator;
fileIOGen1->ResetIndex();
while ( fileIOGen1->CreateFilePath( &fileIO1 ) )
{
if (fileIO1 == "")
fileIOPerm1 = gcnew FileIOPermission(PermissionState::None);
else
fileIOPerm1 = gcnew FileIOPermission(FileIOPermissionAccess::Read, fileIO1);
Console::WriteLine( "**********************************************************\n" );
fileIOGen2->ResetIndex();
while ( fileIOGen2->CreateFilePath( &fileIO2 ) )
{
if (fileIO2 == "")
fileIOPerm2 = gcnew FileIOPermission(PermissionState::None);
else
fileIOPerm2 = gcnew FileIOPermission(FileIOPermissionAccess::Read, fileIO2);
try
{
if ( fileIOPerm2 == nullptr )
continue;
String^ firstPermission = fileIO1 == "" || fileIO1 == nullptr ? "null" : fileIO1;
String^ secondPermission = fileIO2 == "" || fileIO2 == nullptr ? "null" : fileIO2;
fileIOPerm3 = dynamic_cast<FileIOPermission^>(fileIOPerm1->Union( fileIOPerm2 ));
fileIOPerm3 = fileIOPerm1->Union( fileIOPerm2 );
if ( fileIOPerm3 == nullptr )
{
Console::WriteLine( "The union of {0} and {1} is null.", firstPermission, secondPermission );
}
else
{
Console::WriteLine( "The union of {0} and {1} = \n\t{2}", firstPermission, secondPermission, (dynamic_cast<FileIOPermission^>(fileIOPerm3))->GetPathList( FileIOPermissionAccess::Read )[ 0 ] );
}
}
catch ( Exception^ e )
{
Console::WriteLine( "An exception was thrown for union {0}", e );
returnValue = false;
}
}
}
return returnValue;
}
// Intersect creates and returns a new permission that is the intersection of the current
// permission and the permission specified.
bool IntersectDemo()
{
bool returnValue = true;
String^ fileIO1;
String^ fileIO2;
FileIOPermission^ fileIOPerm1;
FileIOPermission^ fileIOPerm2;
FileIOPermission^ fileIOPerm3;
FileIOGenerator^ fileIOGen1 = gcnew FileIOGenerator;
FileIOGenerator^ fileIOGen2 = gcnew FileIOGenerator;
fileIOGen1->ResetIndex();
while ( fileIOGen1->CreateFilePath ( &fileIO1 ) )
{
if (fileIO1 == "")
fileIOPerm1 = gcnew FileIOPermission(PermissionState::None);
else
fileIOPerm1 = gcnew FileIOPermission(FileIOPermissionAccess::Read, fileIO1);
Console::WriteLine( "**********************************************************\n" );
fileIOGen2->ResetIndex();
while ( fileIOGen2->CreateFilePath( &fileIO2 ) )
{
if (fileIO2 == "")
fileIOPerm2 = gcnew FileIOPermission(PermissionState::None);
else
fileIOPerm2 = gcnew FileIOPermission(FileIOPermissionAccess::Read, fileIO2);
String^ firstPermission = fileIO1 == "" || fileIO1 == nullptr ? "null" : fileIO1;
String^ secondPermission = fileIO2 == "" || fileIO2 == nullptr ? "null" : fileIO2;
try
{
fileIOPerm3 = dynamic_cast<FileIOPermission^>(fileIOPerm1->Intersect( fileIOPerm2 ));
if ( fileIOPerm3 != nullptr && fileIOPerm3->GetPathList( FileIOPermissionAccess::Read ) != nullptr )
{
Console::WriteLine( "The intersection of {0} and \n\t{1} = \n\t{2}", firstPermission, secondPermission, (dynamic_cast<FileIOPermission^>(fileIOPerm3))->GetPathList( FileIOPermissionAccess::Read )[ 0 ] );
}
else
{
Console::WriteLine( "The intersection of {0} and {1} is null.", firstPermission, secondPermission );
}
}
catch ( Exception^ e )
{
Console::WriteLine( "An exception was thrown for intersection {0}", e );
returnValue = false;
}
}
}
return returnValue;
}
//Copy creates and returns an identical copy of the current permission.
bool CopyDemo()
{
bool returnValue = true;
String^ fileIO1;
FileIOPermission^ fileIOPerm1;
FileIOPermission^ fileIOPerm2;
FileIOGenerator^ fileIOGen1 = gcnew FileIOGenerator;
FileIOGenerator^ fileIOGen2 = gcnew FileIOGenerator;
fileIOGen1->ResetIndex();
while ( fileIOGen1->CreateFilePath( &fileIO1 ) )
{
if (fileIO1 == "")
fileIOPerm1 = gcnew FileIOPermission(PermissionState::None);
else
fileIOPerm1 = gcnew FileIOPermission(FileIOPermissionAccess::Read, fileIO1);
Console::WriteLine( "**********************************************************\n" );
fileIOGen2->ResetIndex();
try
{
fileIOPerm2 = dynamic_cast<FileIOPermission^>(fileIOPerm1->Copy());
if ( fileIOPerm2 != nullptr )
{
Console::WriteLine( "Result of copy = {0}\n", fileIOPerm2 );
}
else
{
Console::WriteLine( "Result of copy is null. \n" );
}
}
catch ( Exception^ e )
{
{
if ( fileIO1->Equals( "" ) )
{
Console::WriteLine( "The target FileIOPermission is empty, copy failed." );
}
else
Console::WriteLine( e );
}
continue;
}
}
return returnValue;
}
// ToXml creates an XML encoding of the permission and its current state;
// FromXml reconstructs a permission with the specified state from the XML encoding.
bool ToFromXmlDemo()
{
bool returnValue = true;
String^ fileIO1;
FileIOPermission^ fileIOPerm1;
FileIOPermission^ fileIOPerm2;
FileIOGenerator^ fileIOGen1 = gcnew FileIOGenerator;
FileIOGenerator^ fileIOGen2 = gcnew FileIOGenerator;
fileIOGen1->ResetIndex();
while ( fileIOGen1->CreateFilePath( &fileIO1 ) )
{
if (fileIO1 == "")
fileIOPerm1 = gcnew FileIOPermission(PermissionState::None);
else
fileIOPerm1 = gcnew FileIOPermission(FileIOPermissionAccess::Read, fileIO1);
Console::WriteLine( "********************************************************\n" );
fileIOGen2->ResetIndex();
try
{
fileIOPerm2 = gcnew FileIOPermission( PermissionState::None );
fileIOPerm2->FromXml( fileIOPerm1->ToXml() );
Console::WriteLine( "Result of ToFromXml = {0}\n", fileIOPerm2 );
}
catch ( Exception^ e )
{
Console::WriteLine( "ToFromXml failed :{0}{1}", fileIOPerm1, e );
continue;
}
}
return returnValue;
}
// AddPathList adds access for the specified files and directories to the existing state of the permission.
// SetPathList sets the specified access to the specified files and directories, replacing the existing state
// of the permission.
// GetPathList gets all files and directories that have the specified FileIOPermissionAccess.
bool SetGetPathListDemo()
{
try
{
Console::WriteLine( "********************************************************\n" );
FileIOPermission^ fileIOPerm1;
Console::WriteLine( "Creating a FileIOPermission with AllAccess rights for 'C:\\Examples\\Test\\TestFile.txt" );
fileIOPerm1 = gcnew FileIOPermission( FileIOPermissionAccess::AllAccess,"C:\\Examples\\Test\\TestFile.txt" );
Console::WriteLine( "Adding 'C:\\Temp' to the write access list, and \n 'C:\\Examples\\Test' to read access." );
fileIOPerm1->AddPathList( FileIOPermissionAccess::Write, "C:\\Temp" );
fileIOPerm1->AddPathList( FileIOPermissionAccess::Read, "C:\\Examples\\Test" );
array<String^>^paths = fileIOPerm1->GetPathList( FileIOPermissionAccess::Read );
Console::WriteLine( "Read access before SetPathList = " );
IEnumerator^ myEnum = paths->GetEnumerator();
while ( myEnum->MoveNext() )
{
String^ path = safe_cast<String^>(myEnum->Current);
Console::WriteLine( "\t{0}", path );
}
Console::WriteLine( "Setting the read access list to \n'C:\\Temp'" );
fileIOPerm1->SetPathList( FileIOPermissionAccess::Read, "C:\\Temp" );
paths = fileIOPerm1->GetPathList( FileIOPermissionAccess::Read );
Console::WriteLine( "Read access list after SetPathList = " );
IEnumerator^ myEnum1 = paths->GetEnumerator();
while ( myEnum1->MoveNext() )
{
String^ path = safe_cast<String^>(myEnum1->Current);
Console::WriteLine( "\t{0}", path );
}
paths = fileIOPerm1->GetPathList( FileIOPermissionAccess::Write );
Console::WriteLine( "Write access list after SetPathList = " );
IEnumerator^ myEnum2 = paths->GetEnumerator();
while ( myEnum2->MoveNext() )
{
String^ path = safe_cast<String^>(myEnum2->Current);
Console::WriteLine( "\t{0}", path );
}
Console::WriteLine( "Write access = \n{0}", fileIOPerm1->GetPathList( FileIOPermissionAccess::AllAccess ) );
}
catch ( ArgumentException^ e )
{
// FileIOPermissionAccess.AllAccess can not be used as a parameter for GetPathList.
Console::WriteLine( "An ArgumentException occurred as a result of using AllAccess. This property cannot be used as a parameter in GetPathList because it represents more than one type of file variable access. : \n{0}", e );
}
return true;
}
// The AllFiles property gets or sets the permitted access to all files.
// The AllLocalFiles property gets or sets the permitted access to all local files.
bool AllFilesDemo()
{
try
{
Console::WriteLine( "********************************************************\n" );
FileIOPermission^ fileIOPerm1;
Console::WriteLine( "Creating a FileIOPermission and adding read access for all files" );
fileIOPerm1 = gcnew FileIOPermission( FileIOPermissionAccess::AllAccess,"C:\\Examples\\Test\\TestFile.txt" );
fileIOPerm1->AllFiles = FileIOPermissionAccess::Read;
Console::WriteLine( "AllFiles access = {0}", fileIOPerm1->AllFiles );
Console::WriteLine( "Adding AllAccess rights for local files." );
fileIOPerm1->AllLocalFiles = FileIOPermissionAccess::AllAccess;
Console::WriteLine( "AllLocalFiles access = {0}", fileIOPerm1->AllLocalFiles );
}
catch ( ArgumentException^ e )
{
Console::WriteLine( e );
return false;
}
return true;
}
public:
// Invoke all demos.
bool RunDemo()
{
bool ret = true;
bool retTmp;
// Call the IsSubsetOfPath demo.
if ( retTmp = IsSubsetOfDemo() )
Console::WriteLine( "IsSubsetOf demo completed successfully." );
else
Console::WriteLine( "IsSubsetOf demo failed." );
ret = retTmp && ret;
// Call the Union demo.
if ( retTmp = UnionDemo() )
Console::WriteLine( "Union demo completed successfully." );
else
Console::WriteLine( "Union demo failed." );
ret = retTmp && ret;
// Call the Intersect demo.
if ( retTmp = IntersectDemo() )
Console::WriteLine( "Intersect demo completed successfully." );
else
Console::WriteLine( "Intersect demo failed." );
ret = retTmp && ret;
// Call the Copy demo.
if ( retTmp = CopyDemo() )
Console::WriteLine( "Copy demo completed successfully." );
else
Console::WriteLine( "Copy demo failed." );
ret = retTmp && ret;
// Call the ToFromXml demo.
if ( retTmp = ToFromXmlDemo() )
Console::WriteLine( "ToFromXml demo completed successfully." );
else
Console::WriteLine( "ToFromXml demo failed." );
ret = retTmp && ret;
// Call the SetGetPathList demo.
if ( retTmp = SetGetPathListDemo() )
Console::WriteLine( "SetGetPathList demo completed successfully." );
else
Console::WriteLine( "SetGetPathList demo failed." );
ret = retTmp && ret;
// Call the AllFiles demo.
if ( retTmp = AllFilesDemo() )
Console::WriteLine( "AllFiles demo completed successfully." );
else
Console::WriteLine( "AllFiles demo failed." );
ret = retTmp && ret;
return (ret);
}
};
// Test harness.
int main()
{
try
{
FileIOPermissionDemo^ democase = gcnew FileIOPermissionDemo;
bool ret = democase->RunDemo();
if ( ret )
{
Console::WriteLine( "FileIOPermission demo completed successfully." );
Console::WriteLine( "Press the Enter key to exit." );
Console::ReadLine();
System::Environment::ExitCode = 100;
}
else
{
Console::WriteLine( "FileIOPermission demo failed." );
Console::WriteLine( "Press the Enter key to exit." );
Console::ReadLine();
System::Environment::ExitCode = 101;
}
}
catch ( Exception^ e )
{
Console::WriteLine( "FileIOPermission demo failed" );
Console::WriteLine( e );
Console::WriteLine( "Press the Enter key to exit." );
Console::ReadLine();
System::Environment::ExitCode = 101;
}
}
// This sample demonstrates the IsSubsetOf, Union, Intersect, Copy,
// ToXml, FromXml, GetPathList and SetPathList methods, and the
// AllFiles and AllLocalFiles properties
// of the FileIOPermission class.
import System.*;
import System.Security.*;
import System.Security.Permissions.*;
import System.Collections.*;
/** @assembly CLSCompliant(true)
*/
public class FileIOPermissionDemo
{
// IsSubsetOf determines whether the current permission is a
// subset of the specified permission.
// This method compares various FileIOPermission paths with
// FileIOPermissionAccess set to AllAccess.
private boolean IsSubsetOfDemo()
{
boolean returnValue = true;
String fileIO1[] = new String[1] ;
String fileIO2[] = new String[1] ;
FileIOPermission fileIOPerm1[] = new FileIOPermission[1] ;
FileIOPermission fileIOPerm2[] = new FileIOPermission[1] ;
FileIOGenerator fileIOGen1 = new FileIOGenerator();
FileIOGenerator fileIOGen2 = new FileIOGenerator();
fileIOGen1.ResetIndex();
while(fileIOGen1.CreateFilePath(fileIOPerm1, fileIO1,
FileIOPermissionAccess.AllAccess)) {
if (fileIOPerm1[0] == null) {
continue ;
}
Console.WriteLine("***********************"
+ "***********************************\n");
fileIOGen2.ResetIndex();
while(fileIOGen2.CreateFilePath(fileIOPerm2, fileIO2,
FileIOPermissionAccess.AllAccess)) {
String firstPermission = (fileIO1[0].equals("") ==
true | fileIO1[0] == null) ? "null" : fileIO1[0];
String secondPermission = (fileIO2[0].equals("") ==
true | fileIO2[0] == null) ? "null" : fileIO2[0];
if (fileIOPerm2[0] == null) {
continue ;
}
try {
if (fileIOPerm1[0].IsSubsetOf(fileIOPerm2[0])) {
Console.WriteLine((firstPermission
+ " is a subset of "
+ secondPermission + "\n"));
}
else {
Console.WriteLine((firstPermission
+ " is not a subset of "
+ secondPermission + "\n"));
}
}
catch(System.Exception e) {
Console.WriteLine(("An exception was thrown for subset :"
+ ((fileIO1[0].equals("") == true) ?
"null" : (fileIO1[0] + "\n"
+ ((fileIO2[0].equals("") == true) ?
"null" : fileIO2[0]) + "\n" + e))));
}
}
}
return returnValue ;
} //IsSubsetOfDemo
// Union creates a new permission that is the union of the current
// permission and the specified permission.
private boolean UnionDemo()
{
boolean returnValue = true;
String fileIO1[] = new String[1];
String fileIO2[] = new String[1];
FileIOPermission fileIOPerm1[] = new FileIOPermission[1];
FileIOPermission fileIOPerm2[] = new FileIOPermission[1];
IPermission fileIOPerm3;
FileIOGenerator fileIOGen1 = new FileIOGenerator();
FileIOGenerator fileIOGen2 = new FileIOGenerator();
fileIOGen1.ResetIndex();
while(fileIOGen1.CreateFilePath(fileIOPerm1,
fileIO1, FileIOPermissionAccess.Read)) {
if (fileIO1[0] == null) {
continue ;
}
Console.WriteLine("*****************************"
+ "*****************************\n");
fileIOGen2.ResetIndex();
while(fileIOGen2.CreateFilePath(fileIOPerm2,
fileIO2, FileIOPermissionAccess.Read)) {
try {
if (fileIOPerm2[0] == null) {
continue ;
}
String firstPermission = (fileIO1[0].equals("")==
true | fileIO1[0] == null) ? "null" : fileIO1[0];
String secondPermission = (fileIO2[0].equals("") ==
true | fileIO2[0] == null) ? "null" : fileIO2[0];
fileIOPerm3 =((FileIOPermission)(fileIOPerm1[0].
Union(fileIOPerm2[0])));
fileIOPerm3 = fileIOPerm1[0].Union(fileIOPerm2[0]);
if (fileIOPerm3 == null) {
Console.WriteLine(("The union of "
+ firstPermission + " and "
+ secondPermission
+ " is null."));
}
else {
Console.WriteLine(("The union of " + firstPermission
+ " and " + secondPermission + " = \n\t"
+ ((FileIOPermission)(fileIOPerm3)).
GetPathList(FileIOPermissionAccess.Read).
get_Item( 0)));
}
}
catch(System.Exception e) {
Console.WriteLine(("An exception was "
+ "thrown for union " + e));
returnValue = false;
}
}
}
return returnValue ;
} //UnionDemo
// Intersect creates and returns a new permission that is
// the intersection of the current
// permission and the permission specified.
private boolean IntersectDemo()
{
boolean returnValue = true;
String fileIO1[] = new String[1];
String fileIO2[] = new String[1];
FileIOPermission fileIOPerm1[] = new FileIOPermission[1];
FileIOPermission fileIOPerm2[] = new FileIOPermission[1];
FileIOPermission fileIOPerm3;
FileIOGenerator fileIOGen1 = new FileIOGenerator();
FileIOGenerator fileIOGen2 = new FileIOGenerator();
fileIOGen1.ResetIndex();
while(fileIOGen1.CreateFilePath(fileIOPerm1, fileIO1,
FileIOPermissionAccess.Read)) {
if (fileIO1[0] == null) {
continue ;
}
Console.WriteLine("***************************"
+ "*******************************\n");
fileIOGen2.ResetIndex();
while(fileIOGen2.CreateFilePath(fileIOPerm2, fileIO2,
FileIOPermissionAccess.Read)) {
if ( fileIOPerm2[0] == null ) {
continue ;
}
String firstPermission = (fileIO1[0].equals("") ==
true | fileIO1[0] == null) ? "null" : fileIO1[0];
String secondPermission = (fileIO2[0].equals("") ==
true | fileIO2[0] == null) ? "null" : fileIO2[0];
try {
fileIOPerm3 =((FileIOPermission)(fileIOPerm1[0].
Intersect(fileIOPerm2[0])));
if (fileIOPerm3 != null &&
fileIOPerm3.GetPathList(FileIOPermissionAccess.Read)
!= null) {
Console.WriteLine(("The intersection of "
+ firstPermission + " and \n\t"
+ secondPermission + " = \n\t"
+ ((FileIOPermission)(fileIOPerm3)).
GetPathList(FileIOPermissionAccess.Read).
get_Item( 0)));
}
else {
Console.WriteLine(("The intersection of "
+ firstPermission + " and "
+ secondPermission + " is null."));
}
}
catch(System.Exception e) {
Console.WriteLine(("An exception was "
+ "thrown for intersection " + e));
returnValue = false;
}
}
}
return returnValue ;
} //IntersectDemo
//Copy creates and returns an identical copy of the current permission.
private boolean CopyDemo()
{
boolean returnValue = true;
String fileIO1[] = new String[1];
FileIOPermission fileIOPerm1[] = new FileIOPermission[1];
FileIOPermission fileIOPerm2[] = new FileIOPermission[1];
FileIOGenerator fileIOGen1 = new FileIOGenerator();
FileIOGenerator fileIOGen2 = new FileIOGenerator();
fileIOGen1.ResetIndex();
while(fileIOGen1.CreateFilePath(fileIOPerm1, fileIO1,
FileIOPermissionAccess.Read)) {
if (fileIO1 == null) {
continue ;
}
Console.WriteLine("**********************************"
+ "************************\n");
fileIOGen2.ResetIndex();
try {
fileIOPerm2[0] =((FileIOPermission)(fileIOPerm1[0].Copy()));
if (fileIOPerm2[0] != null) {
Console.WriteLine(("Result of copy = "
+ fileIOPerm2[0].ToString() + "\n"));
}
else {
Console.WriteLine("Result of copy is null. \n");
}
}
catch(System.Exception e) {
if (fileIO1[0].Equals("")) {
Console.WriteLine("The target FileIOPermission "
+ "is empty, copy failed.");
}
else {
Console.WriteLine(e);
}
}
continue ;
}
return returnValue ;
} //CopyDemo
// ToXml creates an XML encoding of the permission and its current state;
// FromXml reconstructs a permission with the specified state from the XML
// encoding.
private boolean ToFromXmlDemo()
{
boolean returnValue = true;
String fileIO1[] = new String[1];
FileIOPermission fileIOPerm1[] = new FileIOPermission[1];
FileIOPermission fileIOPerm2[] = new FileIOPermission[1];
FileIOGenerator fileIOGen1 = new FileIOGenerator();
FileIOGenerator fileIOGen2 = new FileIOGenerator();
fileIOGen1.ResetIndex();
while(fileIOGen1.CreateFilePath(fileIOPerm1, fileIO1,
FileIOPermissionAccess.Read)) {
if (fileIOPerm1[0] == null) {
continue ;
}
Console.WriteLine("**********************************"
+ "**********************\n");
fileIOGen2.ResetIndex();
try {
fileIOPerm2[0] = new FileIOPermission(PermissionState.None);
fileIOPerm2[0].FromXml(fileIOPerm1[0].ToXml());
Console.WriteLine(("Result of ToFromXml = "
+ fileIOPerm2[0].ToString() + "\n"));
}
catch(System.Exception e) {
Console.WriteLine(("ToFromXml failed :"
+ fileIOPerm1[0].ToString() + e));
continue ;
}
}
return returnValue ;
} //ToFromXmlDemo
// AllAccess
// AddPathList adds access for the specified files and directories to the
// existing state of the permission.
// SetPathList sets the specified access to the specified files and
// directories, replacing the existing state of the permission.
// GetPathList gets all files and directories that have the specified
// FileIOPermissionAccess.
private boolean SetGetPathListDemo()
{
try {
Console.WriteLine("****************************"
+ "****************************\n");
FileIOPermission fileIOPerm1;
Console.WriteLine("Creating a FileIOPermission with AllAccess "
+ "rights for 'C:\\Examples\\Test\\TestFile.txt");
fileIOPerm1 = new FileIOPermission(
FileIOPermissionAccess.AllAccess,
"C:\\Examples\\Test\\TestFile.txt");
Console.WriteLine("Adding 'C:\\Temp' to the write access "
+ "list, and \n " + "'C:\\Examples\\Test' to read access.");
fileIOPerm1.AddPathList(FileIOPermissionAccess.Write, "C:\\Temp");
fileIOPerm1.AddPathList(FileIOPermissionAccess.Read,
"C:\\Examples\\Test");
String paths[] = fileIOPerm1.GetPathList(
FileIOPermissionAccess.Read);
Console.WriteLine("Read access before SetPathList = ");
for (int iCtr = 0; iCtr < paths.length; iCtr++) {
String path = paths[iCtr];
Console.WriteLine(("\t" + path));
}
Console.WriteLine("Setting the read access list to \n'C:\\Temp'");
fileIOPerm1.SetPathList(FileIOPermissionAccess.Read, "C:\\Temp");
paths = fileIOPerm1.GetPathList(FileIOPermissionAccess.Read);
Console.WriteLine("Read access list after SetPathList = ");
for (int iCtr = 0; iCtr < paths.length; iCtr++) {
String path = paths[iCtr];
Console.WriteLine(("\t" + path));
}
paths = fileIOPerm1.GetPathList(FileIOPermissionAccess.Write);
Console.WriteLine("Write access list after SetPathList = ");
for (int iCtr = 0; iCtr < paths.length; iCtr++) {
String path = paths[iCtr];
Console.WriteLine(("\t" + path));
}
Console.WriteLine(("Write access = \n"
+ fileIOPerm1.GetPathList(FileIOPermissionAccess.AllAccess)));
}
catch(ArgumentException e){
// FileIOPermissionAccess.AllAccess can not be used as a
// parameter for GetPathList.
Console.WriteLine(("An ArgumentException occurred as a result "
+ "of using AllAccess. " + "This property cannot be used as a "
+ "parameter in GetPathList "
+ "because it represents more than one type of "
+ "file variable access. : \n" + e));
}
return true ;
} //SetGetPathListDemo
// The AllFiles property gets or sets the permitted access to all files.
// The AllLocalFiles property gets or sets the permitted access to
// all local files.
private boolean AllFilesDemo()
{
try {
Console.WriteLine("***************************************"
+ "*****************\n");
FileIOPermission fileIOPerm1;
Console.WriteLine("Creating a FileIOPermission and adding "
+ "read access for all files");
fileIOPerm1 = new FileIOPermission(
FileIOPermissionAccess.AllAccess,
"C:\\Examples\\Test\\TestFile.txt");
fileIOPerm1.set_AllFiles ( FileIOPermissionAccess.Read);
Console.WriteLine(("AllFiles access = "
+ fileIOPerm1.get_AllFiles()));
Console.WriteLine("Adding AllAccess rights for local files.");
fileIOPerm1.set_AllLocalFiles (FileIOPermissionAccess.AllAccess);
Console.WriteLine(("AllLocalFiles access = "
+ fileIOPerm1.get_AllLocalFiles()));
}
catch(ArgumentException e) {
Console.WriteLine(e);
return false ;
}
return true ;
} //AllFilesDemo
// Invoke all demos.
public boolean RunDemo()
{
boolean ret = true;
boolean retTmp;
// Call the IsSubsetOfPath demo.
if (retTmp = IsSubsetOfDemo()) {
Console.get_Out().WriteLine("IsSubsetOf demo completed "
+ "successfully.");
}
else {
Console.get_Out().WriteLine("IsSubsetOf demo failed.");
}
ret = retTmp && ret;
// Call the Union demo.
if (retTmp = UnionDemo()) {
Console.get_Out().WriteLine("Union demo completed successfully.");
}
else {
Console.get_Out().WriteLine("Union demo failed.");
}
ret = retTmp && ret;
// Call the Intersect demo.
if (retTmp = IntersectDemo()) {
Console.get_Out().WriteLine("Intersect demo completed "
+ "successfully.");
}
else {
Console.get_Out().WriteLine("Intersect demo failed.");
}
ret = retTmp && ret;
// Call the Copy demo.
if (retTmp = CopyDemo()) {
Console.get_Out().WriteLine("Copy demo completed successfully.");
}
else {
Console.get_Out().WriteLine("Copy demo failed.");
}
ret = retTmp && ret;
// Call the ToFromXml demo.
if (retTmp = ToFromXmlDemo()) {
Console.get_Out().WriteLine("ToFromXml demo completed "
+ "successfully.");
}
else {
Console.get_Out().WriteLine("ToFromXml demo failed.");
}
ret = retTmp && ret;
// Call the SetGetPathList demo.
if (retTmp = SetGetPathListDemo()) {
Console.get_Out().WriteLine("SetGetPathList demo completed "
+ "successfully.");
}
else {
Console.get_Out().WriteLine("SetGetPathList demo failed.");
}
ret = retTmp && ret;
// Call the AllFiles demo.
if (retTmp = AllFilesDemo()) {
Console.get_Out().WriteLine("AllFiles demo completed "
+ "successfully.");
}
else {
Console.get_Out().WriteLine("AllFiles demo failed.");
}
ret = retTmp && ret;
return ret ;
} //RunDemo
// Test harness.
public static void main(String[] args)
{
try {
FileIOPermissionDemo democase = new FileIOPermissionDemo();
boolean ret = democase.RunDemo();
if (ret) {
Console.get_Out().WriteLine("FileIOPermission demo "
+ "completed successfully.");
Console.get_Out().WriteLine("Press the Enter key to exit.");
String consoleInput = Console.ReadLine();
System.Environment.set_ExitCode(100);
}
else {
Console.get_Out().WriteLine("FileIOPermission demo failed.");
Console.get_Out().WriteLine("Press the Enter key to exit.");
String consoleInput = Console.ReadLine();
System.Environment.set_ExitCode(101);
}
}
catch(System.Exception e) {
Console.get_Out().WriteLine("FileIOPermission demo failed");
Console.WriteLine(e.ToString());
Console.get_Out().WriteLine("Press the Enter key to exit.");
String consoleInput = Console.ReadLine();
System.Environment.set_ExitCode(101);
}
} //main
} //FileIOPermissionDemo
// This class generates FileIOPermission objects.
class FileIOGenerator
{
private String myFile[] = {"C:\\Examples\\Test\\TestFile.txt",
"C:\\Examples\\Test\\", "C:\\Examples\\Test\\..", "C:\\Temp"};
private FileIOPermissionAccess myAccess[] = {
FileIOPermissionAccess.AllAccess,
FileIOPermissionAccess.Append,
FileIOPermissionAccess.NoAccess,
FileIOPermissionAccess.PathDiscovery,
FileIOPermissionAccess.Read,
FileIOPermissionAccess.Write};
private int fileIndex = 0;
public FileIOGenerator()
{
ResetIndex();
} //FileIOGenerator
public void ResetIndex()
{
fileIndex = 0;
} //ResetIndex
// Create a FileIOPermission using FileIOPermissionAccess
// that is passed in.
public boolean CreateFilePath(FileIOPermission fileIOPerm[], String file[],
FileIOPermissionAccess fpa)
{
if (fileIndex == myFile.length) {
fileIOPerm[0] = new FileIOPermission(PermissionState.None);
file[0] = "";
fileIndex++;
return true ;
}
if (fileIndex > myFile.length) {
fileIOPerm[0] = null;
file[0] = "";
return false ;
}
file[0] = myFile[fileIndex++];
try {
fileIOPerm[0] = new FileIOPermission(fpa, file[0]);
return true ;
}
catch(System.Exception e) {
Console.WriteLine(("Cannot create FileIOPermission: "
+ file[0] + " " + e));
fileIOPerm[0] = new FileIOPermission(PermissionState.None);
file[0] = "";
return true ;
}
} //CreateFilePath
} //FileIOGenerator
继承层次结构
System.Object
System.Security.CodeAccessPermission
System.Security.Permissions.FileIOPermission
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
FileIOPermission 成员
System.Security.Permissions 命名空间
FileIOPermissionAccess
FileIOPermissionAttribute