首页 > Web开发 > 详细

保存文件到当前项目中 适用于项目中的文件上传

时间:2015-04-15 18:38:15      阅读:281      评论:0      收藏:0      [点我收藏+]
 1 string f = System.AppDomain.CurrentDomain.BaseDirectory.ToString();//获取项目当前目录
 2 
 3 //保存地址
 4 string savePath = "\\files\\网站发布\\" + string.Format("{0:yyyy-MM-dd}", DateTime.Now) + "\\" + fbwzID + "\\" + mTpxx.TPBT + ".html";//虚拟路径
 5 string FilePath = f + savePath;//绝对物理路径(文件真正保存的位置)
 6 
 7 
 8 if (!Directory.Exists(Path.GetDirectoryName(FilePath)))
 9 {
10 //创建路径
11 Directory.CreateDirectory(Path.GetDirectoryName(FilePath));
12 }
13 
14 //创建HTML文件,写入HTML,全路径带扩展名
15 File.Delete(FilePath);
16 File.AppendAllText(FilePath, strHtml.ToString(), Encoding.Default);

保存文件到当前项目中 适用于项目中的文件上传

原文:http://www.cnblogs.com/zecVip/p/4429167.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!