Open XML的上传、下载 、删除 ......文件路径
2015-10-08 13:59
399 查看
/// <summary> /// Get download site, if download tempfolder not existed, create it first /// </summary> /// <param name="filePath">the template file path</param> /// <returns>download path</returns> private string GetDownloadFilePath(string filePath) { string downloadFilePath = ""; if (!string.IsNullOrEmpty(filePath)) { string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1); fileName = fileName.Substring(0, fileName.LastIndexOf(".")) + "_" + DateTime.Now.ToString("yyyyMMddHHmmssffff", System.Globalization.DateTimeFormatInfo.InvariantInfo);//add current time to the fileName downloadFilePath = Utility.GetAppSetting("TempDirectory_Download"); //if download temp folder not existed, create it if (!Directory.Exists(downloadFilePath)) { Directory.CreateDirectory(downloadFilePath); } downloadFilePath += fileName + filePath.Substring(filePath.LastIndexOf(".")); } return downloadFilePath; } /// <summary> /// delete the temp files which were not created by today /// </summary> /// <param name="filePath">the temp directory for download</param> private void DeletePreviousDayData(string filePath) { try { if (!string.IsNullOrEmpty(filePath) && filePath.LastIndexOf("_") > 0) { string currentDay = filePath.Substring(filePath.LastIndexOf("_") + 1, 8); string folderPath = Utility.GetAppSetting("TempDirectory_Download"); if (Directory.Exists(folderPath)) { foreach (string entry in Directory.GetFileSystemEntries(folderPath)) { if (File.Exists(entry) && entry.LastIndexOf("_") > 0) { if (entry.Substring(entry.LastIndexOf("_") + 1).Length == 23)//yyyyMMddHHmmssffff + .docm { string generateDate = entry.Substring(entry.LastIndexOf("_") + 1, 8); if (generateDate != currentDay) { File.Delete(entry); } } } } } } } catch { } }
/// <summary> /// Copy file to temp path /// </summary> /// <param name="path1">file full path</param> /// <param name="path2">the temp full path to be copied to</param> /// <returns></returns> private string CopyFileToTempServer(string path1, string path2) { string errMsg = ""; try { FileInfo fi = new FileInfo(path1); //delete file which generated at previous day in the temp file DeletePreviousDayData(path2); FileInfo fi1 = new FileInfo(path2); if (fi1.Exists) { fi1.Delete(); } //copy to the temp folder if (fi.Exists) { fi.CopyTo(path2); } } catch { errMsg = "Copy file to " + path2 + " failed. Maybe you don't have its permission, or the temp file couldnot be update f or its readonly, please check it!";// += ex.ToString(); } return errMsg; }
相关文章推荐
- 通过 Apache 配置 Rewrite 支持 .htaccess
- Ubuntu15.10下Hadoop2.6.0伪分布式环境安装配置及Hadoop Streaming的体验
- bnuoj 24250 Binary Operations (概率DP)
- grep -q用于if逻辑判断
- CentOS5.x系统 配置YUM服务器
- Apache 与 php的配置
- Tomcat源码分析——类加载体系
- linux:用户和组文件解释(/etc/passwd、/etc/shadow、/etc/group、/etc/gshadow)
- linux上安装nginx简单几步
- Unix/linux学习笔记-------彻底理解管道
- Linux日志分析
- remote desktop connection manager的配置示例
- Android开发时遇到问题比较实用的工具和网站
- centos6 编译安装gcc4.8.2
- 用BSF + Beanshell使Java程序能够运行字符串形式的代码(转载)
- CentOS忘记root密码解决办法
- jmeter 之 BSF,BeanShell(转载)
- linux常用命令(67):echo 命令
- Apache的AB测试介绍
- Apache的AB测试介绍