提取.zip文件时出错 [英] Error While Extracting .zip File

查看:808
本文介绍了提取.zip文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我用以下代码解压缩文件。



Hi,

I have used the following code to unzip the file.

public static void Decompress(FileInfo fi)
   {
       // Get the stream of the source file.
       using (FileStream inFile = fi.OpenRead())
       {
           // Get original file extension, for example
           // "doc" from report.doc.gz.
           string curFile = fi.FullName;
           string origName = curFile.Remove(curFile.Length -
                   fi.Extension.Length);

           //Create the decompressed file.
           using (FileStream outFile = File.Create(origName))
           {
               using (GZipStream Decompress = new GZipStream(inFile,
                       CompressionMode.Decompress))
               {
                   // Copy the decompression stream
                   // into the output file.
                   Decompress.CopyTo(outFile);
                   Console.WriteLine("Decompressed: {0}", fi.Name);
               }
           }
       }
   }





当我运行此代码时,我得到以下错误,



When I run this code I get the following error,

Error   1   'System.IO.Compression.GZipStream' does not contain a definition for 'CopyTo' and no extension method 'CopyTo' accepting a first argument of type 'System.IO.Compression.GZipStream' could be found (are you missing a using directive or an assembly reference?)   E:\POC\FileOperations.aspx.cs   70  32  E:\POC\







我是否需要添加任何参考,或者我错过了任何代码...




Do I need to add any reference, or Am I missing any code ...

推荐答案

来自StackOverFlow:
From StackOverFlow :

Stream.CopyTo只到达。 NET 4 - 它可能不在Mono中(或者你可能需要更新版本。

Stream.CopyTo only arrived in .NET 4 - it may not be in Mono yet (or perhaps you need a more recent version.



它'虽然很容易编写类似的扩展方法:


It's easy to write a similar extension method though:

public static class StreamExtensions
{
    public static void CopyTo(this Stream input, Stream output)
    {
        byte[] buffer = new byte[16 * 1024];
        int bytesRead;
        while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
        {
            output.Write(buffer, 0, bytesRead);
        }
    }
}


CopyTo在.NET Framework 4+中可用

将项目重新定位到.NET4或更高版本。



但是如果你不能创建一个扩展方法。

参见这个 [ ^ ] SO问题。
CopyTo is available in .NET Framework 4+
Re-target your project to .NET4 or higher.

But if you can't then create an extension method.
See this[^] SO question.


解决此错误,因为如何修复winzip错误



指南 http://www.fixwinziperrors.winzipfix.com 将为您提供很多提示如何轻松实现
Solve this error out due to how to fix error for winzip

Guide http://www.fixwinziperrors.winzipfix.com will give you a lot of hints how to make it easy


这篇关于提取.zip文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆