Javatpoint Logo
Javatpoint Logo

C# Program to Demonstrate the Use of the CreateSubdirectory Method

In this article, we will discuss a C# program to illustrate the use of the CreateSubdirectory() method in C#. But before going to its implementation, we must know about the CreateSubdirectory() method.

What is the CreateSubdirectory() method?

In the .NET Framework, the C# Directory class offers static methods for creating subdirectories and other directories, as well as copying, moving, and deleting them. Before using the Directory class, we must import the System.IO namespace. The DirectoryInfo class is part of the System.IO namespace that is used to create, delete, and move directories. Methods are available to execute operations on directories and subdirectories.

The DirectoryInfo class contains different methods to perform different operations. As shown below, this class contains the CreateSubdirectory() method for creating a subdirectory. Here, the method shown is applies to this example of the DirectoryInfo class.

Syntax:

It has the following syntax:

Here, source_path refers to the specified path.

Return value: It will return the last directory of the path.

Exception:

ArgumentException: It raises this exception if the source_path does not have a valid file path or it contains the invalid DirectoryInfo.

ArgumentNullException: If the given source path is null, it raises this exception.

DirectoryNotFoundException: If the path mentioned is invalid, it arises.

IOException: The IO exception is raised if the subdirectory is not created.

PathTooLongException: This exception is raised if the specified path, file name, or both exceed a system-defined maximum length.

SecurityException: If the caller function doesn't have access to the code.

NotSupportedException: If the path has a semicolon (J, it is not part of the specified drive label (for example, "E:\").

Example:

Let us take a program to implement the CreateSubdirectory() method in C#.

Output:

C#_Programs subdirectory is created successfully.

Next TopicCamel case in C#





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA




news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news