Export (0) Print
Expand All

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

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

-or-

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

-or-

The directory is the application's current working directory.

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.

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

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.

Directory.Move

DirectoryInfo.MoveTo

Delete a directory.

Directory.Delete

DirectoryInfo.Delete

Create a subdirectory.

CreateSubdirectory

See the files in a directory.

Name

See the subdirectories of a directory.

GetDirectories

GetDirectories

See all the files in all subdirectories of a directory.

GetFileSystemInfos

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

Community Additions

ADD
Show:
© 2015 Microsoft