This article will show you how you can validate or check
whether directory in a path exists or not using c#.net in windows application.
Some of my previous articles are as follows: Image
Save In XML and Load XML Bitmap Image File in Windows Application Using C#.Net,
How
to Save Record in XML File and Read XML to Display in DataGridview Using C#.net
in Windows Application, How
to Add HyperLink and Retrieve Row Value on Link Click in DataGridView #,
Windows application, Splash
Screen With Please Wait OR Loading Message in C#.net in Windows Application,
Save
Panel with Control Inside It as Image C#.net, VB.net in windows application.
So for this article first we will create a new windows
application and add a textbox and a button control. After adding all controls
your form will looks as shown below.
Now add the below code on button click of the form.
using System;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
//Validate
Directory Exist or Not in C#.Net In Windows Application
private
void button1_Click(object
sender, EventArgs e)
{
if
(Directory.Exists(txtPath.Text))
{
MessageBox.Show("Directory already exists.");
}
else
{
MessageBox.Show("Directory DOES NOT exists.");
}
}
}
}
|
Now run the application to check the output. We will
validate a demo folder at a given path.
Now add the path and click on validate.
Now click on button. You will get the directory already
exist message. Now add a change the directory name and click on validate.
0 comments:
Please let me know your view