Export (0) Print
Expand All

FileIOPermission.GetPathList Method

Gets all files and directories with the specified FileIOPermissionAccess.

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

public string[] GetPathList (
	FileIOPermissionAccess access
)
public String[] GetPathList (
	FileIOPermissionAccess access
)
public function GetPathList (
	access : FileIOPermissionAccess
) : String[]

Parameters

access

One of the FileIOPermissionAccess values that represents a single type of file access.

Return Value

An array containing the paths of the files and directories to which access specified by the access parameter is granted.

Exception typeCondition

ArgumentException

access is not a valid value of FileIOPermissionAccess.

-or-

access is AllAccess, which represents more than one type of file access, or NoAccess, which does not represent any type of file access.

Use this method to get the state of the current permission. To get the state of both Read and Write access, two calls to this method are required.

NoteNote

The access parameter is limited to the values of FileIOPermissionAccess, which represent single types of file access. Those values are Read, Write, Append, and PathDiscovery. The values acceptable to access do not include NoAccess and AllAccess, which do not represent single types of file access.

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

// AllAccess
// AddPathList adds access for the specified files and directories to the 
// existing state of the permission.
// SetPathList sets the specified access to the specified files and 
// directories, replacing the existing state of the permission.
// GetPathList gets all files and directories that have the specified 
// FileIOPermissionAccess.
private boolean 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 = ");
        for (int iCtr = 0; iCtr < paths.length; iCtr++) {
            String path = paths[iCtr];
            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 = ");
        for (int iCtr = 0; iCtr < paths.length; iCtr++) {
            String path = paths[iCtr];
            Console.WriteLine(("\t" + path));
        }            
        
        paths = fileIOPerm1.GetPathList(FileIOPermissionAccess.Write);
        Console.WriteLine("Write access list after SetPathList = ");
        for (int iCtr = 0; iCtr < paths.length; iCtr++) {
            String path = paths[iCtr];
            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 ;
} //SetGetPathListDemo   

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft