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 ...
随机推荐
- nginx配置文件企业优化
1.1 企业规范优化Nginx配置文件 第一个里程碑:创建扩展目录,生成虚拟主机配置文件 mkdir extra sed -n '10,15p' nginx.conf >extra/www.co ...
- case when null then 'xx' else 'yy' end 无效
Sql Server 中使用case when then 判断某字段是否为null,和判断是否为字符或数字时的写法不一样,而且语法能正常执行, 如果不注意数据内容,很容易搞错. 错误方法: CASE ...
- Mysql 查看表数据以及索引大小
如果想查看 Mysql 数据库的总的数据量或者某个表的数据或者索引大小,可以使用系统库 information_schema 来查询,这个系统库中有一个 TABLES 表,这个表是用来记录数据库中表的 ...
- oracle数据库代码块
--申明变量.游标 declare a ):'; --逻辑 begin INSERT into TEMP_DSF.TEST VALUES (a); end; tips:mysql不支持匿名块.仅在存储 ...
- 移动测试之appium+python 简单例子(五)
# coding=utf-8 from appium import webdriver import time import unittest import os import HTMLTestRun ...
- Big Data Opportunities and Challenges(by周志华)论文要点
大数据环境下的机器学习 三种误解:模型不再重要(大量数据上复杂模型依然提升显著,大数据是的复杂模型充分利用数据且难以过拟合),相关性就足够了(因果关系重要性无法被替代),以前的研究方向不再重要(高性能 ...
- RTT设备与驱动之SPI
SPI全双工设备的操作分为主设备和从设备(可以多个,多线程下从设备访问主设备要先获得总线控制权) rt_device_t rt_device_find(const char* name);查找设备 s ...
- [转]dataTables-使用详细说明整理
本文转自:http://blog.csdn.net/mickey_miki/article/details/8240477 本文共四部分:官网 | 基本使用|遇到的问题|属性表 一:官方网站:[htt ...
- Linux的cron服务
可以用以下命令启动和停止服务: /sbin/service crond start /sbin/service crond stop /sbin/service crond restart /sbin ...
- 利用nginx的fastcgi_cache模块来做缓存
nginx不仅有个大家很熟悉的缓存代理后端内容的proxy_cache,还有个被很多人忽视的fastcgi_cache. proxy_cache的作用是缓存后端服务器的内容,可能是任何内容,包括静态的 ...