如何使用 sevenzipsharp 提取文件
how to basically extract file with sevenzipsharp
我将使用 sevenzipsharp 从 iso 文件中提取文件到 usb。为此,我从 vs nuget 包管理器下载了 sevenzipsharp 并编写了(实际上我不能:))这段代码。我没有收到任何错误,但它不工作。我在哪里犯错?请详细写下。
if (IntPtr.Size == 8) //x64
{
SevenZip.SevenZipExtractor.SetLibraryPath(@"C:\Program Files-Zipz.dll");
}
else //x86
{
SevenZip.SevenZipCompressor.SetLibraryPath(@"C:\Program Files (x86)-Zipz.dll");
}
using (var file = new SevenZipExtractor(sourcePath))
{
file.ExtractArchive(outputPath);
}
提前致谢
对于 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();
//...
}
}
}
}
}
}
我将使用 sevenzipsharp 从 iso 文件中提取文件到 usb。为此,我从 vs nuget 包管理器下载了 sevenzipsharp 并编写了(实际上我不能:))这段代码。我没有收到任何错误,但它不工作。我在哪里犯错?请详细写下。
if (IntPtr.Size == 8) //x64
{
SevenZip.SevenZipExtractor.SetLibraryPath(@"C:\Program Files-Zipz.dll");
}
else //x86
{
SevenZip.SevenZipCompressor.SetLibraryPath(@"C:\Program Files (x86)-Zipz.dll");
}
using (var file = new SevenZipExtractor(sourcePath))
{
file.ExtractArchive(outputPath);
}
提前致谢
对于 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();
//...
}
}
}
}
}
}