FileIOPermission.GetPathList(FileIOPermissionAccess) メソッド

定義

指定した FileIOPermissionAccess を含むすべてのファイルとディレクトリを取得します。

public:
 cli::array <System::String ^> ^ GetPathList(System::Security::Permissions::FileIOPermissionAccess access);
public string[] GetPathList (System.Security.Permissions.FileIOPermissionAccess access);
member this.GetPathList : System.Security.Permissions.FileIOPermissionAccess -> string[]
Public Function GetPathList (access As FileIOPermissionAccess) As String()

パラメーター

access
FileIOPermissionAccess

ファイル アクセスの単一の型を表す FileIOPermissionAccess 値の 1 つです。

戻り値

String[]

access パラメーターで指定されたアクセスが付与されているファイルおよびディレクトリのパスを含む配列です。

例外

accessFileIOPermissionAccess の正しい値ではありません。

- または -

accessAllAccess で、ファイル アクセスの 2 つ以上の型を表しているか、NoAccess がファイル アクセスのどの型も表していません。

次のコード例は、 メソッドの使用方法を GetPathList 示しています。 この例は、 クラスに対して提供されるより大きな例の FileIOPermission 一部です。

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;
}
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;
}
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

注釈

現在のアクセス許可の状態を取得するには、このメソッドを使用します。 と Write の両方Readのアクセスの状態を取得するには、このメソッドを 2 回呼び出す必要があります。

Note

パラメーターは access 、 の値 FileIOPermissionAccessに制限されます。これは、単一の種類のファイル アクセスを表します。 これらの値は、 ReadWriteAppend、および PathDiscoveryです。 と を含NoAccessAllAccessめないように指定accessできる値。これは、単一の種類のファイル アクセスを表しません。

適用対象