Tuesday, February 7, 2012

Deleting directory using ASP.Net


Deleting a directory using ASP.Net

This program will delete a directory from your system’s hard disk. Include the following namespace to write the program. It will delete all files and subdirectory also.
Using System.IO;
  • Within if condition it is checking wheather directory is exhists or not.
  • Within try block it will delete the directory

protected void Page_Load(object sender, EventArgs e)
    {
        if (System.IO.Directory.Exists("D:\\abc"))
        {
            try
            {
                System.IO.Directory.Delete("D:\\abc", true);
            }

            catch (System.IO.IOException ex)
            {
                Response.Write(ex.Message);
            }
        }

No comments:

Post a Comment