FileIOPermission.SetPathList メソッド

定義

指定したファイルおよびディレクトリに対する指定したアクセスを設定し、アクセス許可の既存の状態を置き換えます。Sets the specified access to the specified files and directories, replacing the existing state of the permission.

オーバーロード

SetPathList(FileIOPermissionAccess, String)

指定したアクセスを指定したファイルまたはディレクトリに設定し、既存のアクセス許可の状態を置き換えます。Sets the specified access to the specified file or directory, replacing the existing state of the permission.

SetPathList(FileIOPermissionAccess, String[])

指定したアクセスを指定したファイルとディレクトリに設定し、指定したアクセスの現在の状態を新しいパスのセットで置き換えます。Sets the specified access to the specified files and directories, replacing the current state for the specified access with the new set of paths.

SetPathList(FileIOPermissionAccess, String)

指定したアクセスを指定したファイルまたはディレクトリに設定し、既存のアクセス許可の状態を置き換えます。Sets the specified access to the specified file or directory, replacing the existing state of the permission.

public:
 void SetPathList(System::Security::Permissions::FileIOPermissionAccess access, System::String ^ path);
public void SetPathList (System.Security.Permissions.FileIOPermissionAccess access, string path);
member this.SetPathList : System.Security.Permissions.FileIOPermissionAccess * string -> unit
Public Sub SetPathList (access As FileIOPermissionAccess, path As String)

パラメーター

access
FileIOPermissionAccess

FileIOPermissionAccess 値のビットごとの組み合わせ。A bitwise combination of the FileIOPermissionAccess values.

path
String

ファイルまたはディレクトリの絶対パス。The absolute path of the file or directory.

例外

access パラメーターが FileIOPermissionAccess の有効な値ではありません。The access parameter is not a valid value of FileIOPermissionAccess.

または-or- path パラメーターが有効な文字列ではありません。The path parameter is not a valid string.

または-or- path パラメーターで、ファイルまたはディレクトリへの絶対パスが指定されませんでした。The path parameter did not specify the absolute path to the file or directory.

次のコード例は、FileIOPermission.SetPathList(FileIOPermissionAccess, String) メソッドの使用方法を示しています。The following code example shows the use of the FileIOPermission.SetPathList(FileIOPermissionAccess, String) method.

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

注釈

指定されたアクセスの種類に対する現在のアクセス許可の以前の状態が上書きされます。The previous state of the current permission for the specified access type is overwritten. 次のコードは、C:\temp へのアクセスを Readに設定します。The following code sets the access for C:\temp to Read.

fileIOPerm1->SetPathList(FileIOPermissionAccess::Read, "C:\\temp");
fileIOPerm1.SetPathList(FileIOPermissionAccess.Read, "C:\\temp");
fileIOPerm1.SetPathList(FileIOPermissionAccess.Read, "C:\\temp")

アクセスの種類が同じではないため、このアクセスは次のコードでは上書きされません。This access will not be overwritten by the following code because the access types are not the same.

fileIOPerm1->SetPathList(FileIOPermissionAccess::Write, "C:\\documents");
fileIOPerm1.SetPathList(FileIOPermissionAccess.Write, "C:\\documents");
fileIOPerm1.SetPathList(FileIOPermissionAccess.Write, "C:\\documents")

SetPathList(FileIOPermissionAccess, String[])

指定したアクセスを指定したファイルとディレクトリに設定し、指定したアクセスの現在の状態を新しいパスのセットで置き換えます。Sets the specified access to the specified files and directories, replacing the current state for the specified access with the new set of paths.

public:
 void SetPathList(System::Security::Permissions::FileIOPermissionAccess access, cli::array <System::String ^> ^ pathList);
public void SetPathList (System.Security.Permissions.FileIOPermissionAccess access, string[] pathList);
member this.SetPathList : System.Security.Permissions.FileIOPermissionAccess * string[] -> unit
Public Sub SetPathList (access As FileIOPermissionAccess, pathList As String())

パラメーター

access
FileIOPermissionAccess

FileIOPermissionAccess 値のビットごとの組み合わせ。A bitwise combination of the FileIOPermissionAccess values.

pathList
String[]

ファイルとディレクトリの絶対パスを格納する配列。An array containing the absolute paths of the files and directories.

例外

access パラメーターが FileIOPermissionAccess の有効な値ではありません。The access parameter is not a valid value of FileIOPermissionAccess.

または-or- pathList パラメーター内のエントリが正しい文字列ではありません。An entry in the pathList parameter is not a valid string.

注釈

指定されたアクセスの種類に対する現在のアクセス許可の以前の状態が上書きされます。The previous state of the current permission for the specified access type is overwritten. 次のコードは、C:\temp へのアクセスを Readに設定します。The following code sets the access for C:\temp to Read.

アクセスの種類が同じではないため、このアクセスは次のコードでは上書きされません。This access will not be overwritten by the following code because the access types are not the same.

fileIOPerm1->SetPathList(FileIOPermissionAccess::Write, gcnew array<String^> {"C:\\pictures", "C:\\music"});
fileIOPerm1.SetPathList(FileIOPermissionAccess.Write, new string[] {"C:\\pictures", "C:\\music"});
fileIOPerm1.SetPathList(FileIOPermissionAccess.Write, New String() {"C:\\pictures", "C:\\music"})

適用対象