string pathstr = System.Web.HttpContext.Current.Server.MapPath("/FilePath"); if (Directory.Exists(pathstr)) { //获取指定路径下所有文件夹 //string[] folderPaths = Directory.GetDirectories(pathstr); //foreach (string folderPath in folderPaths) // Directory.Delete(folderPath, true); //获取指定路径下所有文件 string[] filePaths = Directory.GetFiles(pathstr); foreach (string itme in filePaths) { System.IO.File.Delete(itme); } }