星空网 > 软件开发 > ASP.net

asp.net(C#)文件操作

//创建文件夹路径

string path = "\\Files\\";

//判断文件夹是否存在

if (!Directory.Exists(path))
{
     Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/" + path)); //不存在,则创建。
}

 

//原模版

string oldfile="\\oldfile\\模版.xls";

//复制后的模版

string newfile=System.AppDomain.CurrentDomain.BaseDirectory + path +"新模版.xls";

//判断文件是否存在

if(File.Exists(newfile))

{

     File.Delete(newfile); //删除

}

//复制文件

File.Copy(HttpContext.Current.Server.MapPath("~/" + oldfile),newfile);

//对模版进行操作,写入内容,然后导出Excel

.......................................

//导出成功后,删除文件夹下的模版文件,以防止日后文件逐渐增多,对网站带来不必要的影响。

//判断文件是否存在

if(File.Exists(newfile))

{

     File.Delete(newfile); //删除

}

 




原标题:asp.net(C#)文件操作

关键词:ASP.NET

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流