读书人

ICSharpCode.SharpZipLib.Zip(a zip

发布时间: 2013-02-06 14:02:21 作者: rapoo

ICSharpCode.SharpZipLib.Zip(a zip file in memory) 高手忙!
大家好,有一个关于ICSharpCode.SharpZipLib.Zip压缩的问题

比方说有两个文件"C:\1.txt", "C:\2.txt"
然后
ZipFile Zip = ZipFile.Create(Memory)
...
Zip.Add("C:\1.txt");
Zip.Add("C:\2.txt");
...

成功压缩后拉链里面的目录为:
test.zip
|-- 1.txt
|-- 2.txt

我想问一下,怎样才能在zip里面创建目录,然后把文件根据需求分别放到不同的目录里,
像:
text.zip
|-- Succ
|-- 1.txt
|-- Error
|-- 2.txt


非常感谢大家! SharpZipLib.Zip 压缩文件
[解决办法]
http://stackoverflow.com/questions/4733707/zip-subfolders-using-zipoutputstream

//Create the right arborescence within the archive
string stFileName = fi.FullName.Remove(0, stDirToZip.Length + 1);
ZipEntry entry = new ZipEntry(stFileName);
[解决办法]

引用:
引用:那LZ能不能用一种方法变通一下

在压缩之前create两个文件夹
把相应的文件move进去

到时候压缩的时候add这两个文件夹
那压缩出来不就达到LZ的需求了么

谢谢您的回复,您的提议非常好,但是因为是服务器端进行压缩,所以不想在服务器建立多余的文件夹,还有其他更好的建议吗?


你可以新建在一个temp的文件夹里面 每次上传压缩完之后可以清空该文件

因为对这个zip的dll不是很熟 所以。。。。。


[解决办法]
  class filestream : IStaticDataSource
{
Stream sm = null;
public filestream(string filename)
{
sm = File.Open(filename, FileMode.Open);
}
public Stream GetSource()
{
return sm;
}
}
static void Main(string[] args)
{
var mms = File.Create("D:\\a.zip");
ZipFile Zip = ZipFile.Create(mms);
Zip.BeginUpdate();
Zip.AddDirectory("文件夹1");
Zip.AddDirectory("文件夹2");
Zip.Add(new filestream("D:\\1.txt"), "文件夹1/1.txt");
Zip.Add(new filestream("D:\\2.txt"), "文件夹2/2.txt");
Zip.CommitUpdate();


Zip.Close();
Console.ReadLine();
}

读书人网 >asp.net

热点推荐