C#判断文件及文件夹是否存在

来源:互联网 发布:施工进度计划表软件 编辑:程序博客网 时间:2024/04/27 07:00

using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.IO; public partial class Default3 : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        ShowPic.Visible = false;//初始化不显示        ShowText.Visible = false;//初始化不显示    }    protected void Button1_Click(object sender, EventArgs e)    {         if (Directory.Exists(Server.MapPath("~/upimg/hufu")) == false)//如果不存在就创建file文件夹        {            Directory.CreateDirectory(Server.MapPath("~/upimg/hufu"));        }         //Directory.Delete(Server.MapPath("~/upimg/hufu"), true);//删除文件夹以及文件夹中的子目录,文件            //判断文件的存在         if (File.Exists(Server.MapPath("~/upimg/Data.html")))        {            Response.Write("Yes");             //存在文件         }         else        {            Response.Write("No");            //不存在文件            File.Create(MapPath("~/upimg/Data.html"));//创建该文件         }         string name = GetFiles.FileName;//获取已上传文件的名字        string size = GetFiles.PostedFile.ContentLength.ToString();//获取已上传文件的大小        string type = GetFiles.PostedFile.ContentType;//获取已上传文件的MIME        string postfix = name.Substring(name.LastIndexOf(".") + 1);//获取已上传文件的后缀        string ipath = Server.MapPath("upimg") +"//"+ name;//获取文件的实际路径        string fpath = Server.MapPath("upfile") + "//" + name;        string dpath = "upimg//" + name;//判断写入数据库的虚拟路径         ShowPic.Visible = true;//激活        ShowText.Visible = true;//激活

http://www.51itshare.cn/html/WangLuoBianCheng/6857/

原创粉丝点击