Directory.CreateDirectory Method (String, DirectorySecurity)

Creates all the directories in the specified path, applying the specified Windows security.

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)

public static DirectoryInfo CreateDirectory (
	string path,
	DirectorySecurity directorySecurity
)
public static DirectoryInfo CreateDirectory (
	String path, 
	DirectorySecurity directorySecurity
)
public static function CreateDirectory (
	path : String, 
	directorySecurity : DirectorySecurity
) : DirectoryInfo
Not applicable.

Parameters

path

The directory to create.

directorySecurity

The access control to apply to the directory.

Return Value

A DirectoryInfo object representing the newly created directory.

Exception typeCondition

IOException

The directory specified by path is read-only.

UnauthorizedAccessException

The caller does not have the required permission.

ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.

-or-

path is prefixed with, or contains only a colon character (:).

ArgumentNullException

path is a null reference (Nothing in Visual Basic).

PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters and file names must be less than 260 characters.

DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

NotSupportedException

path contains a colon character (:) that is not part of a drive label ("C:\").

Use this method overload to create a directory with access control, so there is no chance the directory can be accessed before security is applied.

Any and all directories specified in the path parameter are created, unless they already exist or unless some part of path is invalid. The path parameter specifies a directory path, not a file path.

Creating a directory with only the colon (:) character is not supported and causes a NotSupportedException to be thrown.

For a list of common I/O tasks, see Common I/O Tasks.

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show: