Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Directory.CreateDirectory Method (String, DirectorySecurity)

Note: This method is new in the .NET Framework version 2.0.

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



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 or is not empty.


A file with the same name and location specified by path exists.


The directory is the application's current working directory.


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


An attempt was made to create a directory using only the colon character (:).

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.

The following table lists examples of other typical or related I/O tasks.

To do this...

See the example in this topic...

Rename or move a directory.



Delete a directory.



Create a subdirectory.


See the files in a directory.


See the subdirectories of a directory.



See all the files in all subdirectories of a directory.


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
© 2018 Microsoft