标签: dotnetzip

DotNetZip从其他zip的子集创建zip

我有一个大的zip文件,我需要分成多个zip文件.在我正在创建的方法中,我有一个List对象.

这是我得到的代码:

 //All files have the same basefilename/
 string basefilename = Path.GetFileNameWithoutExtension(entries[0].FileName);
 MemoryStream memstream = new MemoryStream();
 ZipFile zip = new ZipFile();
 foreach (var entry in entries)
 {
    string newFileName = basefilename + Path.GetExtension(entry.FileName);
    zip.AddEntry(newFileName, entry.OpenReader());
 }

 zip.Save(memstream);

 //this will later go in an file-io handler class.
 FileStream outstream = File.OpenWrite(@"c:\files\"+basefilename+ ".zip");
 memstream.WriteTo(outstream);
 outstream.Flush();
 outstream.Close();
Run Code Online (Sandbox Code Playgroud)

这是我在save()调用时遇到的错误:

{Ionic.Zlib.ZlibException:在Ionic.Zlib.ZlibBodec.Inflate(FlushType flush)的Ionic.Zlib.InflateManager.Inflate(FlushType flush)中的错误状态(无效块类型),位于Ionic.Zlib.ZlibBaseStream.Read(Byte [] Ionic.Zlib.DeflateStream.Read(Byte []缓冲区,Int32偏移量,Int32计数)的Ionic.Crc.CrcCalculatorStream.Read(Byte []缓冲区,Int32偏移量,Int32计数)的离子,Ionic,Int32偏移量,Int32计数) .Zip.SharedUtilities.ReadWithRetry(Stream s,Byte [] buffer,Int32 offset,Int32 count,String FileName)在离子的Ionic.Zip.ZipEntry.Write(Stream s)的Ionic.Zip.ZipEntry._WriteEntryData(Stream s) .Zip.ZipFile.Save()在Ionic.Zip.ZipFile.Save(Stream outputStream)at at

我究竟做错了什么?

.net c# dotnetzip

3
推荐指数
1
解决办法
5354
查看次数

c# - DotNetZip 从 MemoryStream 打开 zip 文件

我喜欢做的不是将 zip 文件存储在磁盘上,而是从 MemoryStream 打开它。

我正在查看 DotNetZip 编程示例的文档:请注意,我根据我认为可能需要的内容稍微调整了它。

    var ms = new MemoryStream();
    using (ZipFile zip = new ZipFile())
    {
       zip.AddFile("ReadMe.txt");
       zip.AddFile("7440-N49th.png");
       zip.AddFile("2008_Annual_Report.pdf");        
       zip.Save(ms); // this will save the files in memory steam
    }


  // now what I need is for the zip file to open up so that 
     the user can view all the files in it. Not sure what to do next after 
     zip.Save(ms) for this to happen. 
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc dotnetzip

3
推荐指数
1
解决办法
4778
查看次数

dotnetZip如​​何使用memoryStream写入特定文件夹

我需要创建一个包含文件夹结构的zip文件,并能够将文件从内存流添加到特定文件夹.

我试图通过dotnetZip来实现这一点,但他们似乎已经放弃了通过流将文件添加到特定文件夹的支持.

我能找到的所有例子都使用以下内容:

zip.AddEntry("test.txt","folder",memoryStream);

但是此方法不再允许您添加要添加文件的文件夹名称.

zip.AddEntry("test.txt",memoryStream);

如何使用dotnetZip在zip文件中创建子文件夹并将memoryStream文件添加到该文件夹​​而无需保存到磁盘?

.net zip dotnetzip

3
推荐指数
1
解决办法
2105
查看次数

如何将整个文件夹添加到zip存档中

我尝试了一下zip.AddDirectory,但是我不知道如何将整个文件夹导入到存档中(使用DotNetZip)。

想要这样:

在此处输入图片说明

但是这个:

在此处输入图片说明

c# dotnetzip

3
推荐指数
1
解决办法
2551
查看次数

C#:如何在创建zip文件时报告进度?

更新:让它工作更新我的工作代码

这是我到目前为止所拥有的

 private async void ZipIt(string src, string dest)
    {
        await Task.Run(() =>
        {
            using (var zipFile = new ZipFile())
            {
                // add content to zip here 
                zipFile.AddDirectory(src);
                zipFile.SaveProgress +=
                    (o, args) =>
                    {
                        var percentage = (int)(1.0d / args.TotalBytesToTransfer * args.BytesTransferred * 100.0d);
                        // report your progress
                        pbCurrentFile.Dispatcher.Invoke(
                            System.Windows.Threading.DispatcherPriority.Normal,
                            new Action(
                            delegate()
                            {

                                pbCurrentFile.Value = percentage;
                            }
                            ));
                    };
                zipFile.Save(dest);
            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

我需要弄清楚如何更新我的进度条,但不确定我是否在正确的轨道上我已经搜索过并找到了很多关于Windows窗体和vb.net的例子,但是wpf c#没有想知道是否有人可以提供帮助.

c# wpf dotnetzip progress-bar

3
推荐指数
1
解决办法
6774
查看次数

创建并流式传输图像存档 zip 文件以供下载 C#

我正在 MVC3 中使用心爱的 DotNetZip 归档库来动态生成一个 Zip 文件,其中包含来自存储在数据库中的二进制文件的 .png 图像。然后我将生成的 Zip 文件流式传输出来供用户下载。(我在保存到数据库之前验证图像数据,因此您可以假设所有图像数据都是有效的)。

public ActionResult PictureExport()
      {
           IEnumerable<UserPicture> userPictures = db.UserPicture.ToList();
           //"db" is a DataContext and UserPicture is the model used for uploaded pictures.
           DateTime today = DateTime.Now;
           string fileName = "attachment;filename=AllUploadedPicturesAsOf:" + today.ToString() + ".zip";
           this.Response.Clear();
           this.Response.ContentType = "application/zip";
           this.Response.AddHeader("Content-Disposition", fileName);

           using (ZipFile zipFile = new ZipFile())
             {
               using (MemoryStream stream = new MemoryStream())
                {
                 foreach (UserPicture userPicture in userPictures)
                  {
                     stream.Seek(0, SeekOrigin.Begin);
                     string pictureName = userPicture.Name+ ".png";
                     using (MemoryStream tempstream …
Run Code Online (Sandbox Code Playgroud)

c# zip dotnetzip asp.net-mvc-3

2
推荐指数
1
解决办法
8562
查看次数

从 dotnetzip 创建的 zip 文件中提取时出错 - “Windows 无法完成提取。”

我正在使用dotnetzip 动态创建一个 zip 文件,以作为流通过 mvc 返回。

我能够添加已经是流的文件,即动态创建的文件。我还添加了从 base64 字符串创建的文件。

创建和下载 zip 文件很好,当我使用 windows 资源管理器(windows 7 或 8)打开 zip 文件时,我可以按预期看到所有条目。打开从内存流创建的文件打开没有问题,但是当我尝试打开从 base64 字符串创建的文件时,Windows 资源管理器返回错误

Windows 无法完成提取。无法创建目标文件。

如果我尝试将文件从 Windows 资源管理器中的 zip 文件拖到另一个文件夹,我会收到错误消息:

在此处输入图片说明

如果我打开相同的 zip 文件或使用WinRAR 解压缩并打开任何条目,我没有任何问题。

有任何想法吗?我在想也许我需要向 base64 字符串或流添加内容类型?Dotnetzip似乎没有参数来指定内容类型...

我已确保 zip 文件或其任何条目没有加密

c# stream dotnetzip

2
推荐指数
1
解决办法
5360
查看次数

压缩在 C# 中创建的文件夹

我正在 C# 中创建一个文件夹,我希望在创建后立即将其压缩。我环顾四周(如何压缩文件夹),(http://dotnetzip.codeplex.com/)但到目前为止还没有运气。我有点担心使用 dotnetzip,因为它的最后一个版本是 5 年前。

dotnetzip 在 Visual Studio 2015 中是否仍然相关,或者是否有更现代的方式在 C# 中压缩文件夹而不使用包?

这就是我复制文件夹的方式;

    private static void CopyDirectory(string SourcePath, string DestinationPath, bool overwriteexisting)
    {

        SourcePath = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\";
        DestinationPath = DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\";

        if (Directory.Exists(SourcePath))
        {
            if (Directory.Exists(DestinationPath) == false)
                Directory.CreateDirectory(DestinationPath);

            foreach (string fls in Directory.GetFiles(SourcePath))
            {
                FileInfo flinfo = new FileInfo(fls);
                flinfo.CopyTo(DestinationPath + flinfo.Name, overwriteexisting);
            }
            foreach (string drs in Directory.GetDirectories(SourcePath))
            {
                DirectoryInfo drinfo = …
Run Code Online (Sandbox Code Playgroud)

c# zip dotnetzip

2
推荐指数
1
解决办法
3306
查看次数

作为参数传递时,MemoryStream 不可读

昨天我遇到了一个奇怪的问题:当我想传递一个 zip 文件并byte[]读取它时,我得到了一个Ionic.Zip.ZipExpception

无法将其读取为 ZipFile

public string Import(byte[] file)
{
    try
    {
        var stream = new MemoryStream(file);
        if (ZipFile.IsZipFile(stream))
        {
            ImportArchive(stream);
        } else {
            ...
        }
    ...
}

private void ImportArchive(MemoryStream stream)
{
    var zip = ZipFile.Read(stream); //--> ZipException thrown
    ...
}
Run Code Online (Sandbox Code Playgroud)

现在,如果我传递byte[]as 参数而不是MemoryStream,一切正常:

public string Import(byte[] file)
{
    try
    {                
        if (ZipFile.IsZipFile(new MemoryStream(file), true))
        {
            ImportArchive(file);
        } else {
            ...
        }
    ...
}

private void ImportArchive(byte[] file)
{
    var fileStream = new …
Run Code Online (Sandbox Code Playgroud)

c# memorystream dotnetzip

2
推荐指数
1
解决办法
4108
查看次数

使用Ionic.Zip在asp中创建zip文件时如何将文件夹添加到文件夹

我能够.zip使用AddDirectoryByName和成功创建一个文件AddFile,我的代码如下:-

using (ZipFile zip = new ZipFile())
{
    zip.AlternateEncodingUsage = ZipOption.AsNecessary;
    zip.AddDirectoryByName("A");
    zip.AddFile("~/.png", "A");
}
Run Code Online (Sandbox Code Playgroud)

但发生的情况是,它按名称创建一个文件夹,A 并在其中添加一个文件(例如.png)。

但是我想将此文件夹A放在另一个名为“Root”的文件夹中,那么现在如何创建一个名为Root.zip 的文件夹并将文件夹添加A到该文件夹中Root

感谢任何帮助。

c# asp.net zipfile dotnetzip

2
推荐指数
1
解决办法
1236
查看次数