asp.net(C#)文件操作

王朝学院·作者佚名  2016-05-21
窄屏简体版  字體: 小  |  中  |  大  |  超大  

asp.net(C#)文件操作 Posted on 2015-04-14 14:39 haishu 阅读(...) 评论(...) 编辑 收藏//创建文件夹路径

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); //删除

}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航