How to Create File Directory in C#

Now, let’s learn how to create a file directory in C#. A directory is a container that is used to store and organized files that are arranged according to their importance. This simple program will help you create a file directory with ease. All you have to do is set the path where you want to create the directory in the textbox and it will create automatically. This is the use of System.IO. The System.IO is a namespace that has the capability to read and write files that supply basic file and directory support. Let’s begin:

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application for c#. formFileD

Step 2

Add a Label, Textbox and a Button inside the Form. Form1FileD

Step 3

Open code editor and a namespace to access System.IO libraries.
  1. using System.IO;

Step 4

Double click the “Create” button and do the following codes to create a file directory.
  1.         private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             string directory;
  4.             directory = textBox1.Text;
  5.            
  6.             if (Directory.Exists(directory))
  7.             {
  8.                 MessageBox.Show("Directory is already exist");
  9.             }else
  10.             {
  11.                 Directory.CreateDirectory(directory);
  12.                 MessageBox.Show("Directory has been created");
  13.             }
  14.         }
For any questions about this article. You can contact me @ Email – [email protected] Mobile No. – 09305235027 – TNT Or feel free to comment below.

Add new comment