FileIOPermission::GetPathList Method

Gets all files and directories with the specified FileIOPermissionAccess.

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

public:
array<String^>^ GetPathList(
	FileIOPermissionAccess access
)

Parameters

access
Type: System.Security.Permissions::FileIOPermissionAccess

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

Return Value

Type: array<System::String>
An array containing the paths of the files and directories to which access specified by the access parameter is granted.

ExceptionCondition
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.

The following code example shows the use of the GetPathList method. This example is part of a larger example provided for the FileIOPermission class.

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

.NET Framework

Supported in: 4.5.3, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft