Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SharpZipLib中的奇怪错误——大小是x,但我预期是y_C#_.net_Compression_Zip_Sharpziplib - Fatal编程技术网

C# SharpZipLib中的奇怪错误——大小是x,但我预期是y

C# SharpZipLib中的奇怪错误——大小是x,但我预期是y,c#,.net,compression,zip,sharpziplib,C#,.net,Compression,Zip,Sharpziplib,我使用SharpZipLib时出错了。我有这样的代码 FastZip compressor = new FastZip(); compressor.CreateZip(outputFileName, currentWorkingDirectory, true, ""); 这似乎是正确的。然而,我得到一个ZipException声明 size was 0, but I expected 54 我不知道那是什么意思。任何人都有任何见解或某种API文档的链接吗?是指向他们的源代码和API文档的帮助

我使用SharpZipLib时出错了。我有这样的代码

FastZip compressor = new FastZip();
compressor.CreateZip(outputFileName, currentWorkingDirectory, true, "");
这似乎是正确的。然而,我得到一个ZipException声明

size was 0, but I expected 54

我不知道那是什么意思。任何人都有任何见解或某种API文档的链接吗?

是指向他们的源代码和API文档的帮助文件的链接。

事实证明问题如下。我试图为给定目录中的所有项目创建一个.zip文件,并将该.zip文件放在该目录中。显然,这个库的工作方式是创建.zip文件,然后逐个文件读取目录,写入.zip文件。尝试将.zip文件本身添加到zip时出错!当时可能拒绝访问该文件或其他内容,导致上述错误。简单的修复方法是在不同的目录中创建.ZIP文件。

我通过在ProgressHandler事件处理程序中处理它并将ZIPEntry作为发送方传递,解决了类似的问题。因为这是错误情况,所以我们应该停止进一步处理zip文件e.ContinueRunning应该设置为false

private void ProcessFileHandler(object sender, ProgressEventArgs e)
        {                    
                ZipEntry newEntry = sender as ZipEntry;
                if (newEntry != null)
                {
                    newEntry.Size = e.Processed;
                }
                e.ContinueRunning = keepRunning;
                return;
         }

你有权限写那个文件夹吗?我确实有权在各个方面访问那个文件夹。我弄明白了,我把答案贴在下面。你很接近了,虽然:)刚才有一个类似的问题-原来是一个文件锁定问题,但这给了我正确的方向:)我在ProgressHandler EVENT处理程序中修复了类似的问题,并将Zippentry作为发送方传递
私有void ProcessFileHandler(对象发送方,ProgressEventArgs e){ZipEntry newEntry=作为ZipEntry的发送方;if(newEntry!=null){newEntry.Size=e.Processed;}e.ContinueRunning=keepRunning;return;}