简体   繁体   中英

how to basically extract file with sevenzipsharp

I will extract files to usb from iso file with sevenzipsharp. For this, I download sevenzipsharp from vs nuget package manager and I coded (actually I couldn't :) ) this code . I dont take any error but It isnt working. Where do I make mistakes? Please write details.

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);  
}

Thank you in advance

对于x86,你正在做SevenZip.SevenZipCompressor.SetLibraryPath ,你可能想做SevenZip.SevenZipExtractor.SetLibraryPath

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();
                        //...
                    }
                }
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM