/// <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的上传、下载 、删除 ......文件路径的更多相关文章

  1. java FTP 上传下载删除文件

    在JAVA程序中,经常需要和FTP打交道,比如向FTP服务器上传文件.下载文件,本文简单介绍如何利用jakarta commons中的FTPClient(在commons-net包中)实现上传下载文件 ...

  2. java 通过sftp服务器上传下载删除文件

    最近做了一个sftp服务器文件下载的功能,mark一下: 首先是一个SftpClientUtil 类,封装了对sftp服务器文件上传.下载.删除的方法 import java.io.File; imp ...

  3. 通过代码链接ftp上传下载删除文件

    因为我的项目是Maven项目,首先要导入一个Maven库里的包:pom.xml <dependency>            <groupId>com.jcraft</ ...

  4. Xshell5下利用sftp上传下载传输文件

    sftp是Secure File Transfer Protocol的缩写,安全文件传送协议.可以为传输文件提供一种安全的加密方法.sftp 与 ftp 有着几乎一样的语法和功能.SFTP 为 SSH ...

  5. SpringMVC文件上传下载(单文件、多文件)

    前言 大家好,我是bigsai,今天我们学习Springmvc的文件上传下载. 文件上传和下载是互联网web应用非常重要的组成部分,它是信息交互传输的重要渠道之一.你可能经常在网页上传下载文件,你可能 ...

  6. Struts2 文件上传,下载,删除

    本文介绍了: 1.基于表单的文件上传 2.Struts 2 的文件下载 3.Struts2.文件上传 4.使用FileInputStream FileOutputStream文件流来上传 5.使用Fi ...

  7. SpringMVC ajax技术无刷新文件上传下载删除示例

    参考 Spring MVC中上传文件实例 SpringMVC结合ajaxfileupload.js实现ajax无刷新文件上传 Spring MVC 文件上传下载 (FileOperateUtil.ja ...

  8. 使用C#WebClient类访问(上传/下载/删除/列出文件目录)由IIS搭建的http文件服务器

    前言 为什么要写这边博文呢?其实,就是使用C#WebClient类访问由IIS搭建的http文件服务器的问题花了我足足两天的时间,因此,有必要写下自己所学到的,同时,也能让广大的博友学习学习一下. 本 ...

  9. 使用C#WebClient类访问(上传/下载/删除/列出文件目录)

    在使用WebClient类之前,必须先引用System.Net命名空间,文件下载.上传与删除的都是使用异步编程,也可以使用同步编程, 这里以异步编程为例: 1)文件下载: static void Ma ...

  10. SpringMVC框架(四)文件的上传下载,上下文路径

    文件目录: SpringMVC配置文件: <?xml version="1.0" encoding="UTF-8"?> <beans xmln ...

随机推荐

  1. idea生成springBoot 报错403

    问题: idea创建springboot失败 Initialization failed Cannot download 'https://start.spring.io': Status: 403 ...

  2. redis初步学习 0

    2.1 Redis是什么 REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统.Redis提供了一些丰富的数据 ...

  3. Silverlight TreeView 带 checkbox和图片

    前段时间做Silverlight TreeView 控件,但是要带checkbox和图片,在网上到处找相关的例子,效果图如下 xaml代码 <UserControl x:Class=" ...

  4. 吞吐率(Requests per second),缩写RPS

    计算公式:   吞吐率 = 总请求数 / 处理这些请求的总完成时间   Requests per second = Complete requests / Time taken for tests 吞 ...

  5. C++学习笔记:

    一 友元函数:友元函数没有this指针,不是类的成员,在外部定义无需类标识符,引用全局或者静态对象不需要类对象标识符,而访问非静态对象则需要. 二 类继承:如果不指定继承方式,默认是私有继承.但私有继 ...

  6. javascript中typeof与instanceof的区别

    JavaScript 中 typeof 和 instanceof 常用来判断一个变量是否为空,或者是什么类型的.但它们之间还是有区别的: typeof typeof 是一个一元运算,放在一个运算数之前 ...

  7. 使用Xshell连接服务器

    转载原地址:http://www.server110.com/linux/201308/830.html 1)关于Xshell 网上更多的资料里提到的SSH客户端是putty,因为简单.开源.免费.但 ...

  8. HDU 5418——Victor and World——————【状态压缩+floyd】

    Victor and World Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Other ...

  9. 介绍几个关于C/C++程序调试的函数

    最近调试程序学到的几个挺有用的函数,分享一下,希望对用C/C++的朋友有所帮助! 1. 调用栈系列下面是函数原型: 1 2 3 4 #include "execinfo .h" i ...

  10. Postman+Newman+Jenkins APItest自动化集成测试

    postman做接口测试简单易用很容易上手,但是接口越来越多,每次手动点击runner进行测试不灵活,最近就研究了下newman,利用newman实现接口的自动化测试,但是每次需要命令行操作也不方便, ...