FileIOPermission.SetPathList Method (FileIOPermissionAccess, String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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

Namespace:   System.Security.Permissions
Assembly:  mscorlib (in mscorlib.dll)

public void SetPathList(
	FileIOPermissionAccess access,
	string path


Type: System.Security.Permissions.FileIOPermissionAccess

A bitwise combination of the FileIOPermissionAccess values.

Type: System.String

The absolute path of the file or directory.

Exception Condition

The access parameter is not a valid value of FileIOPermissionAccess.


The path parameter is not a valid string.


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

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.

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

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

private bool SetGetPathListDemo()

        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" +

    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;

.NET Framework
Available since 1.1
Return to top