Folder Creation and Deletion using DirectoryInfo in Asp.Net

Description:-

Is the example to show you how to crate folder in current directory using DirectoryInfo class in dot net.

if (Directory.Exists(String.Format(@"{0}\Temp\", Environment.CurrentDirectory)))
{
  System.IO.DirectoryInfo downloadedMessageInfo = new DirectoryInfo(String.Format(@"{0}\Temp\", Environment.CurrentDirectory));
  foreach (DirectoryInfo dir in downloadedMessageInfo.GetDirectories())
  {
    dir.Delete(true);
  }
  System.GC.Collect();
  System.GC.WaitForPendingFinalizers();
  Directory.Delete(String.Format(@"{0}\Temp\", Environment.CurrentDirectory), true);
}

To Create Directory in Current Directory using Directory Class.

Directory.CreateDirectory(string.Format(@"{0}\Temp", Environment.CurrentDirectory));

Related Posts

Previous
Next Post »

Thanks for comments.....