How to Create File Directory in C#
Submitted by janobe on Friday, December 28, 2018 - 22:42.
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
For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below.
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#.Step 2
Add a Label, Textbox and a Button inside the Form.Step 3
Open code editor and a namespace to access System.IO
libraries.
- using System.IO;
Step 4
Double click the “Create” button and do the following codes to create a file directory.- private void button1_Click(object sender, EventArgs e)
- {
- string directory;
- directory = textBox1.Text;
- if (Directory.Exists(directory))
- {
- MessageBox.Show("Directory is already exist");
- }else
- {
- Directory.CreateDirectory(directory);
- MessageBox.Show("Directory has been created");
- }
- }
Add new comment
- 802 views