FileIOPermission.SetPathList Method

Definition

Sets the specified access to the specified files and directories, replacing the existing state of the permission.

Overloads

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)

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

Sets the specified access to the specified file or directory, replacing the existing state of the permission.

C#
public void SetPathList(System.Security.Permissions.FileIOPermissionAccess access, string path);

Parameters

access
FileIOPermissionAccess

A bitwise combination of the FileIOPermissionAccess values.

path
String

The absolute path of the file or directory.

Exceptions

The access parameter is not a valid value of FileIOPermissionAccess.

-or-

The path parameter is not a valid string.

-or-

The path parameter did not specify the absolute path to the file or directory.

Examples

The following code example shows the use of the FileIOPermission.SetPathList(FileIOPermissionAccess, String) method.

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

Remarks

The previous state of the current permission for the specified access type is overwritten. The following code sets the access for C:\temp to Read.

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

This access will not be overwritten by the following code because the access types are not the same.

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

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

SetPathList(FileIOPermissionAccess, String[])

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

Sets the specified access to the specified files and directories, replacing the current state for the specified access with the new set of paths.

C#
public void SetPathList(System.Security.Permissions.FileIOPermissionAccess access, string[] pathList);

Parameters

access
FileIOPermissionAccess

A bitwise combination of the FileIOPermissionAccess values.

pathList
String[]

An array containing the absolute paths of the files and directories.

Exceptions

The access parameter is not a valid value of FileIOPermissionAccess.

-or-

An entry in the pathList parameter is not a valid string.

Remarks

The previous state of the current permission for the specified access type is overwritten. 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.

C#
fileIOPerm1.SetPathList(FileIOPermissionAccess.Write, new string[] {"C:\\pictures", "C:\\music"});

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10