Compartir a través de


FileIOPermission.SetPathList Método

Definición

Establece el acceso especificado para los archivos y directorios especificados, reemplazando el estado existente del permiso.

Sobrecargas

SetPathList(FileIOPermissionAccess, String)

Establece el acceso especificado al archivo o directorio especificado, reemplazando el estado existente del permiso.

SetPathList(FileIOPermissionAccess, String[])

Establece el acceso especificado a los archivos y directorios especificados, reemplazando el estado actual para el acceso especificado con el nuevo conjunto de rutas de acceso.

SetPathList(FileIOPermissionAccess, String)

Source:
FileIOPermission.cs
Source:
FileIOPermission.cs
Source:
FileIOPermission.cs
Source:
FileIOPermission.cs

Establece el acceso especificado al archivo o directorio especificado, reemplazando el estado existente del permiso.

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)

Parámetros

access
FileIOPermissionAccess

Combinación bit a bit de los valores de FileIOPermissionAccess.

path
String

La ruta de acceso absoluta del directorio o el archivo.

Excepciones

El parámetro access no es un valor válido de FileIOPermissionAccess.

o bien

El parámetro path no es una cadena válida.

o bien

El parámetro path no especificó la ruta de acceso absoluta al archivo o directorio.

Ejemplos

En el ejemplo de código siguiente se muestra el uso del FileIOPermission.SetPathList(FileIOPermissionAccess, String) método .

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

Comentarios

El estado anterior del permiso actual para el tipo de acceso especificado se sobrescribe. El código siguiente establece el acceso de C:\temp en Read.

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

El código siguiente no sobrescribirá este acceso porque los tipos de acceso no son los mismos.

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

Se aplica a

SetPathList(FileIOPermissionAccess, String[])

Source:
FileIOPermission.cs
Source:
FileIOPermission.cs
Source:
FileIOPermission.cs
Source:
FileIOPermission.cs

Establece el acceso especificado a los archivos y directorios especificados, reemplazando el estado actual para el acceso especificado con el nuevo conjunto de rutas de acceso.

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())

Parámetros

access
FileIOPermissionAccess

Combinación bit a bit de los valores de FileIOPermissionAccess.

pathList
String[]

Matriz que contiene las rutas de acceso absolutas de los archivos y directorios.

Excepciones

El parámetro access no es un valor válido de FileIOPermissionAccess.

o bien

Una entrada del parámetro pathList no es una cadena válida.

Comentarios

El estado anterior del permiso actual para el tipo de acceso especificado se sobrescribe. El código siguiente establece el acceso de C:\temp en Read.

El código siguiente no sobrescribirá este acceso porque los tipos de acceso no son los mismos.

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"})

Se aplica a