Help! How to cretate a new directory in a given path in C#.NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to create a new directory in a given path and need to create a file in
that new directory. Any ideas?
 
using System.IO;

string strPath = "what your physical path is"; //ie "C:\\Windows\\System32"

try
{
if (Directory.Exists(strPath))
{
lblDirectoryResult.Text += "That path " + strPath + " already exists.";
return;
}
DirectoryInfo di = Directory.CreateDirectory(strPath);
lblDirectoryResult.Text += "The directory " + strPath + " was created
successfully.";
}
catch (Exception ex)
{
lblDirectoryResult.Text = Convert.ToString(ex.Message);
}

Good luck!
 
THanks mate. This helps a lot.

No Spam said:
using System.IO;

string strPath = "what your physical path is"; //ie "C:\\Windows\\System32"

try
{
if (Directory.Exists(strPath))
{
lblDirectoryResult.Text += "That path " + strPath + " already exists.";
return;
}
DirectoryInfo di = Directory.CreateDirectory(strPath);
lblDirectoryResult.Text += "The directory " + strPath + " was created
successfully.";
}
catch (Exception ex)
{
lblDirectoryResult.Text = Convert.ToString(ex.Message);
}

Good luck!
 
Back
Top