Open XML的上传、下载 、删除 ......文件路径
/// <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("\\") + );
fileName = fileName.Substring(, 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("_") > )
{
string currentDay = filePath.Substring(filePath.LastIndexOf("_") + , );
string folderPath = Utility.GetAppSetting("TempDirectory_Download");
if (Directory.Exists(folderPath))
{
foreach (string entry in Directory.GetFileSystemEntries(folderPath))
{
if (File.Exists(entry) && entry.LastIndexOf("_") > )
{
if (entry.Substring(entry.LastIndexOf("_") + ).Length == )//yyyyMMddHHmmssffff + .docm
{
string generateDate = entry.Substring(entry.LastIndexOf("_") + , );
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;
}
Open XML的上传、下载 、删除 ......文件路径的更多相关文章
- java FTP 上传下载删除文件
在JAVA程序中,经常需要和FTP打交道,比如向FTP服务器上传文件.下载文件,本文简单介绍如何利用jakarta commons中的FTPClient(在commons-net包中)实现上传下载文件 ...
- java 通过sftp服务器上传下载删除文件
最近做了一个sftp服务器文件下载的功能,mark一下: 首先是一个SftpClientUtil 类,封装了对sftp服务器文件上传.下载.删除的方法 import java.io.File; imp ...
- 通过代码链接ftp上传下载删除文件
因为我的项目是Maven项目,首先要导入一个Maven库里的包:pom.xml <dependency> <groupId>com.jcraft</ ...
- Xshell5下利用sftp上传下载传输文件
sftp是Secure File Transfer Protocol的缩写,安全文件传送协议.可以为传输文件提供一种安全的加密方法.sftp 与 ftp 有着几乎一样的语法和功能.SFTP 为 SSH ...
- SpringMVC文件上传下载(单文件、多文件)
前言 大家好,我是bigsai,今天我们学习Springmvc的文件上传下载. 文件上传和下载是互联网web应用非常重要的组成部分,它是信息交互传输的重要渠道之一.你可能经常在网页上传下载文件,你可能 ...
- Struts2 文件上传,下载,删除
本文介绍了: 1.基于表单的文件上传 2.Struts 2 的文件下载 3.Struts2.文件上传 4.使用FileInputStream FileOutputStream文件流来上传 5.使用Fi ...
- SpringMVC ajax技术无刷新文件上传下载删除示例
参考 Spring MVC中上传文件实例 SpringMVC结合ajaxfileupload.js实现ajax无刷新文件上传 Spring MVC 文件上传下载 (FileOperateUtil.ja ...
- 使用C#WebClient类访问(上传/下载/删除/列出文件目录)由IIS搭建的http文件服务器
前言 为什么要写这边博文呢?其实,就是使用C#WebClient类访问由IIS搭建的http文件服务器的问题花了我足足两天的时间,因此,有必要写下自己所学到的,同时,也能让广大的博友学习学习一下. 本 ...
- 使用C#WebClient类访问(上传/下载/删除/列出文件目录)
在使用WebClient类之前,必须先引用System.Net命名空间,文件下载.上传与删除的都是使用异步编程,也可以使用同步编程, 这里以异步编程为例: 1)文件下载: static void Ma ...
- SpringMVC框架(四)文件的上传下载,上下文路径
文件目录: SpringMVC配置文件: <?xml version="1.0" encoding="UTF-8"?> <beans xmln ...
随机推荐
- linux中的目录配置
一.权限对文件的重要性 1.r(read):可读取此文件的实际内容,读取文本文件的文字内容等. 2.w(write):可以编辑,新增或者是修改该文件的内容. 3.x(execute):该文件具有可以被 ...
- Jenkins自动化CI CD流水线之4--Master-Slave架构
一.介绍 jenkins的Master-slave分布式架构主要是为了解决jenkins单点构建任务多.负载较高.性能不足的场景. Master/Slave相当于Server和agent的概念.Mas ...
- 检测客户pc电脑端VC++环境并安装
CefSharp 是一个非常不错的cef封装.但它依赖于VC++环境. 具体如下: Branch CEF Version VC++ Version .Net Version Status master ...
- 轻量级RPC框架-motan
https://github.com/weibocom/motan/wiki/zh_quickstart#%E7%AE%80%E5%8D%95%E8%B0%83%E7%94%A8%E7%A4%BA%E ...
- @RequestParam详解以及加与不加的区别
以前写controller层的时候都是默认带上 @RequestParam 的, 今天发现不加@RequestParam 也能接收到参数 下面我们来区分一下加与不加的区别 这里有两种写法 @Reque ...
- TCP/IP协议<二>
一.TCP/IP的标准化 1.TCP/IP的含义 一般来说,TCP/IP是利用IP进行通信时所必须用到的协议群的统称. 具体点,IP或ICMP.TCP或UDP.TELENT或FTP.以及HTTP等都属 ...
- oracle简单命令
1.cmd 中 sqlplus /nolog 2.SQL> conn sys/password as sysdba
- Day3下
少女[问题描述]你是能看到第一题的 friends呢.—— hja少女在图上开车, 她们希望把每条边分配给与其相连的点中一个并且每个点最多被分配一条边,问可能的方案数.[输入格式]第一行两个整数
- 文件监控只FileSystemWatcher控件
FileSYstemWatcher控件是用来监控一个文件系统或监控文件变化.该控件会通知文件创建.修改.删除的消息,分别通过Created事件.Changed事件和Deleted事件来处理对应的操作 ...
- C# Label背景透明
Label背景透明是相对于Label的Parent而言的,如果Label的Parent是一个winform,而这个winform又有一个PictureBox,现在Label放在PictureBox上, ...