C# Create File / Folder

How To Create File Or Directory In C#

c# create file and directory


In This C# Tutorial  We Will See How To Create File And Folder In CSharp Programming Language.


Project Source Code:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class Form15 : Form
    {
        public Form15()
        {
            InitializeComponent();
        }

       // create file
        private void button1_Click(object sender, EventArgs e)
        {

            string path = textBox1.Text;

            if(!File.Exists(path))
            {
                File.Create(path);
                MessageBox.Show("File Created");
            }
            else
            {
                MessageBox.Show("File Already Exists");
            }

        }

        // create folder
        private void button2_Click(object sender, EventArgs e)
        {
            string path = textBox1.Text;
            if(!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
                MessageBox.Show("Directory Created");
            }
            else
            {
                MessageBox.Show("Directory Already Exists");
            }
        }
    }
}




Share this

Related Posts

Previous
Next Post »