Table of Contents

Class WritePermissionTester

Namespace
CSF.Screenplay.Reporting
Assembly
CSF.Screenplay.dll

Helper class to determine whether or not we have write permission to a specified file path.

public class WritePermissionTester : ITestsPathForWritePermissions
Inheritance
WritePermissionTester
Implements
Inherited Members

Methods

HasWritePermission(string)

Gets a value indicating whether or not the current process has write permission to the specified file path.

public bool HasWritePermission(string path)

Parameters

path string

An absolute or relative file path.

Returns

bool

true if the current process is able to write to the specified path; false if not.

Remarks

The path may be relative or absolute; if relative then it is treated as relative to the current working directory.

This method will recurse in order to test the permissions for parent directories, if it finds a file or directory which does not exist. When testing for the writability of directories, this is performed by attempting to create a temporary file with a random file name; see GetRandomFileName(). If we are able to create such a file then it is assumed that we have full write permissions to the directory. In this scenario, the temporary file is deleted immediately after.

This method will return false if we reach the root directory of the filesystem.