Monday, March 3, 2014

Delete Files from Directory Using Asp.Net.

Here I am going to explain, How can you Delete  Files from Directory (Folder) Using Asp.Net.
Use the Below function for Delete  Files from Directory (Folder).

protected void deletefiles()
    {
        string path = string.Empty;
        path = "Image";  // Your Folder Name
        if (Directory.Exists(HttpContext.Current.Server.MapPath(path)))
        {

            string[] files = System.IO.Directory.GetFiles(HttpContext.Current.Server.MapPath(path));

            foreach (string file in files)
            {

                File.Delete(file);

            }

        }
    }