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 ...
随机推荐
- CAS 5.X 安装
官方文档: https://apereo.github.io/cas/5.1.x/index.html 几个基本概念 CAS Server: SSO服务器端 CAS Client : SSO客户端,内 ...
- MetricStatTimer
package org.apache.storm.metric.internal; import java.util.Timer; /** * Just holds a singleton metri ...
- 斑马条码打印机通过js post 打印
<html lang="zh-ch"><head> <meta charset="utf-8"> <meta ht ...
- Reactive Extensions入门
https://www.cnblogs.com/yangecnu/archive/2012/11/03/Introducting_ReactiveExtensions.html 前面我写过7篇文章粗略 ...
- 第十一章:DOM扩展
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- element-ui表格合并span-method
先看一下合并后的样式,表格第二行,二三四列合并 官网给我们提供了span-method的方法可以进行表格合并,有4个参数返回:row,column,rowIndex,columnIndex;row和c ...
- python-常用模块整理
学习背景 最近需要进行文件夹数据的批量读取,里面会用到python里面的os模块.但是对os模块又不是很熟悉,里面的函数有哪些函数?有什么用?怎么用?英语不好的每次看官方文档也比较费力,所以就想着看看 ...
- Java 之 Serializable 序列化和反序列化的概念,作用的通俗易懂的解释
遇到这个 Java Serializable 序列化这个接口,我们可能会有如下的问题a,什么叫序列化和反序列化b,作用.为啥要实现这个 Serializable 接口,也就是为啥要序列化c,seria ...
- net 总数据中取随机几条数据
List<string> lstSample = new List<string>(); Random rand = new Random(); List<int> ...
- java实现新旧版本号比较
项目中需要使用比较现在线上版本和新版本,然后新版本执行新方法,方法如下: /** * * @方法名称:comparaVersion * @内容摘要: <版本比较> * @param old ...