/// <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. Go语言基础之9--指针类型详解

    一. 变量和内存地址 每个变量都有内存地址,可以说通过变量来操作对应大小的内存 注意:通过&符号可以获取变量的内存地址 通过下面例子来理解下: 实例1-1 package main impor ...

  2. windows下安装TensorFlow(CPU版)

    建议先到anaconda官网下载最新windows版的anaconda3.6,然后按步骤进行安装.(这里我就不贴图了,自己下吧) 1.准备安装包 http://www.lfd.uci.edu/~goh ...

  3. mysql5.7导出到csv

    版本:mysql5.7 SELECT * FROM table_name where xxx into outfile 'C:/ProgramData/MySQL/MySQL Server 5.7/U ...

  4. OpenStack Weekly Rank 2015.08.10

    Module Reviews Drafted Blueprints Completed Blueprints Filed Bugs Resolved Bugs Cinder 5 1 1 6 12 Sw ...

  5. [Silverlight]调用外部可执行程序

    public void InvokeExternalExecutableApp() { if (Application.Current.HasElevatedPermissions) {using ( ...

  6. Collections练习之对字符串先折半,再取最长的一个

    不多说,直接上干货! 代码需求 由 [aa, abcde, cba, cba, nbaa, zzz] 变成 max=abcde CollectionsDemo.java package zhouls. ...

  7. Qt 学习(3)

    Qt 修改 Windows 注册表项 在使用 FT232R 驱动(usb转串口设备)连接电脑时,下位机发送的数据会被转换器缓存起来,由串口转换器驱动设定的延时定时发送到 PC,这样就造成了一个问题:上 ...

  8. 斗鱼扩展--DouyuRoom使用说明(十四)

    1.从 https://pan.baidu.com/s/1yBfZFtcakbDxmyas0VCpRw 下载 DouyuRoom.zip 然后解压到一个目录,我是放在C盘根目录下的,你们随意.然后解压 ...

  9. asp实现网页浏览总数

    <% AlldayView=0 Set Rs=Server.CreateObject("Adodb.RecordSet") Sql="select * from v ...

  10. 多列转1列 SqlServer 实现oracle10g的 wmsys.wm_concat()--for xml path('')

    有这么一个表 )) , 'aa') , 'bb') , 'aaa') , 'bbb') , 'ccc') , 'ddd') , 'fff')                               ...