我设置了以下代码来创建一组doucments的zip文件:
public bool CreateDocumentationZipFile(int documentIdentifier, string zipDestinationPath, IList<string> documentPaths)
{
bool zipped = false;
if (documentPaths.Count > 0)
{
using (ZipFile loanZip = new ZipFile())
{
loanZip.AddFiles(documentPaths, false, zipDestinationPath);
loanZip.Save(string.Format("{0}{1}.zip",zipDestinationPath, documentIdentifier.ToString()));
zipped = true;
}
}
return zipped;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,当创建zip文件时,文件夹结构将保存在zip文件中:
例如
我正在创建一个位于的文档选择的zip文件
C:\ SoftwareDevelopment \分行\ ScannedDocuments \
打开创建的zip文件时,zip中有一个文件夹结构,如下所示:
文件夹1("SoftwareDevelopment")
内部文件夹1是文件夹2("分支")
文件夹2内是文件夹3("ScannedDocuments")
扫描的文档文件夹然后包含实际的扫描文件.
任何人都可以告诉我如何在没有维护文件夹路径的情况下将zip文件放在zip中?
我知道用 ionic.zip 压缩文件,如下所示:
using (var zip = new ZipFile())
{
zip.Encryption = EncryptionAlgorithm.WinZipAes256;
zip.Password = "123";
zip.AddDirectory("/path/");
zip.SaveProgress += Zip_ProgressBar;
zip.Save("/path/");
}
Run Code Online (Sandbox Code Playgroud)
但这段代码允许人们查看加密的文件和文件夹名称。如何防止存档(加密)文件和文件夹名称出现?
我尝试Ionic.Zip.dll从asp.net c#web表单应用程序下载一个zip文件,如下所示:
zip.AddEntry("filename", arraybyte);
Response.Clear();
Response.BufferOutput = false;
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=SuppliersDocuments.zip");
zip.Save(Response.OutputStream);
Response.Close();
Run Code Online (Sandbox Code Playgroud)
但我Failed - network error这样:
错误只发生在chrome中,它在其他浏览器中正常工作.我的localhost上不会发生错误,它只发生在主服务器上.
如果有人可以解释这个问题的解决方案将是非常有帮助的.
我们在zip文件中编码文件时出现问题.我们使用离子拉链来压缩和解压缩档案.我们位于丹麦,所以我们经常在文件名中包含æ,ø或å的文件.
当用户使用Windows内置工具压缩文件时,我发现它正在使用IBM437 enconding,当我们在其中包含'ø'/'Ø'的文件时,这只是给出了一些时髦的结果.我修复了以下代码:
public static string IBM437Encode(this string text)
{
return text.Replace('ø', '¢').Replace('Ø', '¥');
}
public static string IBM437Decode(this string text)
{
return text.Replace('¢', 'ø').Replace('¥', 'Ø');
}
Run Code Online (Sandbox Code Playgroud)
这已经运行了一段时间了,一切都很好.
但是,因为它总是一个但是,我们没有尝试用mac osx中的默认工具压缩的文件.所以现在我们遇到了一个新问题..当使用æ,ø和å时,编码是UTF-8! 所以如果我知道压缩拉链的位置,我可以让它工作,但是有没有简单的方法来检测或规范化拉链内的编码?
正如标题所示,我需要从 zip 文件中读取文件名。我将把名称输入一个二维字符串数组(以及其他数据)。这是我想做的事情的一个开始示例。
private String[,] ArrayFiller(ZipFile MyZip)
{
int count = 0;
ZipFile zipfile = ZipFile.Read();
int zipSize = MyZip.Count;
string[,] MyArr = new string[zipSize, zipSize];
foreach (ZipEntry e in zipfile.EntriesSorted)
{
//otherArr[count,count] = e; -adds the file, but I need title
}
return MyArr;
}
Run Code Online (Sandbox Code Playgroud)
我确信我错过了一些简单的东西,但我似乎无法在 ZipFile 类中找到“文件名”属性。导入的包名为 Ionic.Zip。
也许它是某种压缩对象的属性?