DirectoryInfo.CreateSubdirectory Method (String, DirectorySecurity)

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

Creates a subdirectory or subdirectories on the specified path with the specified security. The specified path can be relative to this instance of the DirectoryInfo class.

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

public DirectoryInfo CreateSubdirectory (
	string path,
	DirectorySecurity directorySecurity
)
public DirectoryInfo CreateSubdirectory (
	String path, 
	DirectorySecurity directorySecurity
)
public function CreateSubdirectory (
	path : String, 
	directorySecurity : DirectorySecurity
) : DirectoryInfo

Parameters

path

The specified path. This cannot be a different disk volume or Universal Naming Convention (UNC) name.

directorySecurity

The security to apply.

Return Value

The last directory specified in path.

Exception typeCondition

ArgumentException

path does not specify a valid file path or contains invalid DirectoryInfo characters.

ArgumentNullException

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

DirectoryNotFoundException

The specified path is invalid, such as being on an unmapped drive.

IOException

The subdirectory cannot be created.

-or-

A file or directory already has the name specified by path.

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. The specified path, file name, or both are too long.

SecurityException

The caller does not have code access permission to create the directory.

-or-

The caller does not have code access permission to read the directory described by the returned DirectoryInfo object. This can occur when the path parameter describes an existing directory.

Any and all directories specified in path are created, unless some part of path is invalid. The path parameter specifies a directory path, not a file path. If the subdirectory already exists, this method does nothing.

NoteNote

Path names are limited to 248 characters.

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

CreateDirectory

Directory

See the files in a directory.

Name

See the subdirectories of a directory.

GetDirectories

GetDirectories

See all the files and all the subdirectories in a directory.

GetFileSystemInfos

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, 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
Show: