Sevenzip extractFile(String file,Stream stream)方法流参数。 C#

时间:2013-06-20 19:46:50

标签: c# visual-studio-2010 7zip

我正在尝试访问.7z文件中的文件。我知道zip文件夹中文件的名称,它存在于.7z文件中。以前我使用过ExtractArchive(templocation),只是将所有文件转储到临时位置。现在我希望能够在不提取整个.7z文件的情况下获取特定文件。

7Zip有一个名为SevenZipExtractor的类,它有一个ExtractFile方法。我认为这就是我要找的东西,但我找不到任何体面的文件。

我需要澄清的是如何正确传递Stream参数。 我正在使用这样的代码;

//this grabs the zip file and creates a FileInfo array that hold the .7z file (assume there is only one) 
DirectoryInfo directoryInfo = new DirectoryInfo(ApplicationPath);
FileInfo[] zipFile = directoryInfo.GetFiles("*.7z");
//This creates the zipextractor on the zip file I just placed in the zipFile FileInfo array
using (SevenZip.SevenZipExtractor zipExtractor = new SevenZip.SevenZipExtractor(zipFile[0].FullName)) 
//Here I should be able to use the ExtractFile method, however I don't understand the stream parameter, and I can't find any good documentation on the method itself. What is this method looking for?
{
    zipExtractor.ExtractFile("ConfigurationStore.xml", Stream stream);
}

1 个答案:

答案 0 :(得分:0)

设置SevenZip可写出的FileStream

DirectoryInfo directoryInfo = new DirectoryInfo(ApplicationPath);
FileInfo[] zipFile = directoryInfo.GetFiles("*.7z");
using (SevenZip.SevenZipExtractor zipExtractor = new SevenZip.SevenZipExtractor(zipFile[0].FullName)) 
{
    using (FileStream fs = new FileStream("", FileMode.Create))  //replace empty string with desired destination
    {
        zipExtractor.ExtractFile("ConfigurationStore.xml", fs);
    }
}