CreateDirectory Method (String, DirectorySecurity)
Collapse the table of content
Expand the table of content

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.



The directory to create.


The access control to apply to the directory.

Return Value

A DirectoryInfo object representing the newly created directory.

Exception typeCondition


The directory specified by path is read-only.


The caller does not have the required permission.


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


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


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


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.


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


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

© 2015 Microsoft