How To Create File Or Directory In C#
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");
}
}
}
}
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");
}
}
}
}