asp.net判断文件或文件夹是否存在

在上传文件时经常要判断文件夹是否存在,如果存在就上传文件,否则新建文件夹再上传文件
判断语句为
if (System.IO.Directory.Exists(Server.MapPath("file")) == false)//如果不存在就创建file文件夹
             {
                 System.IO.Directory.CreateDirectory(Server.MapPath("file"));
             }
System.IO.Directory.Delete(Server.MapPath("file"),true);//删除文件夹以及文件夹中的子目录,文件    

判断文件的存在
if (System.IO.File.Exist(Server.MapPath("~/Back/Data.xml"))
{
//存在文件
}  
else
{
//不存在文件
   Directory.Create(Server.MapPath("~/Back/Data.xml"));//创建该文件
}