最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
C#实现判断文件夹存在与否并创建文件夹的方法
时间:2022-06-25 07:54:11 编辑:袖梨 来源:一聚教程网
代码如下 | 复制代码 |
protectedvoidButton1_Click(objectsender, 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"));//创建该文件 } stringname = GetFiles.FileName;//获取已上传文件的名字 stringsize = GetFiles.PostedFile.ContentLength.ToString();//获取已上传文件的大小 stringtype = GetFiles.PostedFile.ContentType;//获取已上传文件的MIME stringpostfix = name.Substring(name.LastIndexOf(".") + 1);//获取已上传文件的后缀 stringipath = Server.MapPath("upimg") +"\"+ name;//获取文件的实际路径 stringfpath = Server.MapPath("upfile") +"\"+ name; stringdpath ="upimg\"+ name;//判断写入数据库的虚拟路径 ShowPic.Visible =true;//激活 ShowText.Visible =true;//激活 //判断文件格式 if(name =="") { Response.Write(" "); } else{ if(postfix =="jpg"|| postfix =="gif"|| postfix =="bmp"|| postfix =="png") { GetFiles.SaveAs(ipath); ShowPic.ImageUrl = dpath; ShowText.Text ="你上传的图片名称是:"+ name +" } else { ShowPic.Visible =false;//隐藏图片 GetFiles.SaveAs(fpath);//由于不是图片文件,因此转存在upfile这个文件夹 ShowText.Text ="你上传的文件名称是:"+ name +" } } } |
相关文章
- 三国群英传策定九州兑换码是什么 三国群英传策定九州2025最新兑换码大全 10-14
- 寻道大千兑换码大全 2025最新可用兑换码一览 10-14
- 绝区零真斗技能详解 10-14
- 原神千星奇域装扮获取途径 10-14
- 火影忍者手游侠隐佐助有哪些玩法技巧 10-14
- 燕云十六声曲岸妙妙喵在哪-曲岸妙妙喵位置分享 10-14