• 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("\") + 1);
                    fileName = fileName.Substring(0, 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("_") > 0)
                    {
                        string currentDay = filePath.Substring(filePath.LastIndexOf("_") + 1, 8);
                        string folderPath = Utility.GetAppSetting("TempDirectory_Download");
                        if (Directory.Exists(folderPath))
                        {
                            foreach (string entry in Directory.GetFileSystemEntries(folderPath))
                            {
                                if (File.Exists(entry) && entry.LastIndexOf("_") > 0)
                                {
                                    if (entry.Substring(entry.LastIndexOf("_") + 1).Length == 23)//yyyyMMddHHmmssffff + .docm
                                    {
                                        string generateDate = entry.Substring(entry.LastIndexOf("_") + 1, 8);
                                        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;
            }
  • 相关阅读:
    mybatis0206 延迟加载
    怎样关闭“粘滞键”?
    TNS-12557: TNS:protocol adapter not loadable TNS-12560: TNS:protocol adapter error
    HTTP协议头部与Keep-Alive模式详解
    oracle定时器执行一遍就不执行或本就不执行
    Inflation System Properties
    https://stackoverflow.com/questions/16130292/java-lang-outofmemoryerror-permgen-space-java-reflection
    java spring中对properties属性文件加密及其解密
    annotation配置springMVC的方法了事务不起作用
    SQLPlus在连接时通常有四种方式
  • 原文地址:https://www.cnblogs.com/liuwj/p/4860840.html
Copyright © 2020-2023  润新知