Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.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# 如何使用sevenzipsharp基本提取文件_C#_Extract_Sevenzipsharp - Fatal编程技术网

C# 如何使用sevenzipsharp基本提取文件

C# 如何使用sevenzipsharp基本提取文件,c#,extract,sevenzipsharp,C#,Extract,Sevenzipsharp,我将使用sevenzipsharp从iso文件提取文件到usb。为此,我从vs nuget软件包管理器下载了sevenzipsharp,并编写了(实际上我不能:)这段代码。我不接受任何错误,但它不起作用。我在哪里犯错误?请写详细资料 if (IntPtr.Size == 8) //x64 { SevenZip.SevenZipExtractor.SetLibraryPath(@"C:\Program Files\7-Zip\7z.dll"); } else //x86 { Sev

我将使用sevenzipsharp从iso文件提取文件到usb。为此,我从vs nuget软件包管理器下载了sevenzipsharp,并编写了(实际上我不能:)这段代码。我不接受任何错误,但它不起作用。我在哪里犯错误?请写详细资料

if (IntPtr.Size == 8) //x64
{
    SevenZip.SevenZipExtractor.SetLibraryPath(@"C:\Program Files\7-Zip\7z.dll");
}
else //x86
{
    SevenZip.SevenZipCompressor.SetLibraryPath(@"C:\Program Files (x86)\7-Zip\7z.dll");
}
using (var file = new SevenZipExtractor(sourcePath))
{
    file.ExtractArchive(outputPath);  
}

提前感谢您

对于x86,您正在执行
SevenZip.SevenZip compressor.SetLibraryPath
您可能打算执行的
SevenZip.SevenZipExtractor.SetLibraryPath

您能编辑您的答案并更具体一些吗?你们收到了什么错误信息?我编辑了这个问题,感谢你们的关注。即使在编辑之后,你们的问题是什么还不清楚<代码>“我不会犯任何错误。我在哪里会犯错误?请写详细信息。”
从任何角度讲都毫无意义。亲爱的B.K,我对此也感到不舒服,但我不知道为什么它不起作用,我也不知道我可以与你分享什么,因为它不会返回任何结果、错误或其他东西。我只想用c#将一个iso文件解压缩到目录中,你们能帮我一下吗?@HaydarŞAHİN我会逐步检查代码,确保
sourcePath
outputPath
不为空。我还要确保您正在设置SevenZip库路径的路径是实际存在的路径。如果您在x64上运行并且希望它的int指针大小为8,请确保您是为x64或任何CPU构建的。
class Program
{
    const string zipFile = @"D:\downloads\price.zip";

    static void Main(string[] args)
    {
        using (Stream stream = File.OpenRead(zipFile))
        {
            string dllPath = Environment.Is64BitProcess ?
                Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "7z64.dll")
                    : Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "7z.dll");

            SevenZipBase.SetLibraryPath(dllPath);

            Extract(stream);
        }
    }

    static void Extract(Stream archiveStream)
    {
        using (SevenZipExtractor extr = new SevenZipExtractor(archiveStream))
        {
            foreach (ArchiveFileInfo archiveFileInfo in extr.ArchiveFileData)
            {
                if (!archiveFileInfo.IsDirectory)
                {
                    using (var mem = new MemoryStream())
                    {
                        extr.ExtractFile(archiveFileInfo.Index, mem);

                        string shortFileName = Path.GetFileName(archiveFileInfo.FileName);
                        byte[] content = mem.ToArray();
                        //...
                    }
                }
            }
        }
    }
}