【发布时间】:2016-02-04 14:34:25
【问题描述】:
我有一个业务场景,我应该允许将加密文件夹下载为 ZIP 文件;这意味着文件夹及其子文件夹中的文件已加密。当我对文件执行服务器端解密时,首先需要在临时文件夹中重新创建相同的文件夹结构,并解密文件本身并将它们保存到临时文件夹的相应文件夹中。
这部分效果很好;临时文件中的文件夹结构按照应有的方式重新创建,但是当我尝试使用 System.IO.Compression 库创建临时文件夹的 ZIP 文件时出现问题。
当您打开 ZIP 文件时,仅将结构的第一个文件夹创建为文件夹,其余文件夹仅创建为无扩展名文件。
解压应用程序看到的文件夹结构
代码 sn-p:
//Creating temporary folder where the decrypted files will be extracted
var tempFolderPath = _directory.CreateTemporaryFolder(rootFolderPath);
var serverTempFolderPath = HttpContext.Current.Server.MapPath(tempFolderPath);
//Creating the folder structure
RecursiveFolderCreate(folders, tempFolderPath);
//Decrypting the files and recreating them in the corresponding folders
foreach (var file in files)
{
PrepareFile(file, folderPath, tempFolderPath);
}
//Creating the zip file
string zipFileName = string.Concat(folder.Name, ".zip");
string zipFilePath = System.IO.Path.Combine(rootFolderPath, zipFileName);
string serverZipFilePath = HttpContext.Current.Server.MapPath(zipFilePath);
ZipFile.CreateFromDirectory(serverTempFolderPath, serverZipFilePath, CompressionLevel.Optimal, false);
byte[] zipFile = System.IO.File.ReadAllBytes(serverZipFilePath);
【问题讨论】:
标签: c# asp.net asp.net-mvc compression zipfile