All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
asp.net判断文件或文件夹是否存在_[Asp.Net教程]

Writer: 归海一刀 Article type: Programming skills(编程技巧) Time: 2014/1/30 1:19:52 Browse times: 345 Comment times: 0

asp.net判断文件或文件夹是否存在_[Asp.Net教程]


Head photo

Go homepage
Upload pictures
Write articles

asp.net判断文件或文件夹是否存在_[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"));//创建该文件
}




There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.