2013-06-20 63 views
0

我試圖訪問.7z文件中的文件。我知道zip文件夾中文件的名稱,它存在於.7z文件中。以前我使用過ExtractArchive(templocation),它只是將所有文件轉儲到臨時位置。現在我想能夠在不提取整個.7z文件的情況下獲取特定文件。Sevenzip extractFile(String file,Stream stream)方法流參數。 c#

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

是那個方法的唯一版本?有沒有重載將需要目標路徑('字符串)?我問,如果沒有,你可能需要設置一個'FileStream'或類似的東西來寫入。無論如何,重載只會讓你的路徑字符串爲你設置。 – DonBoitnott

回答

0

設置一個FileStream是SevenZip可以寫出來:

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

太棒了!我直盯着msdn上的Stream類!文件流非常不穩定,顯然更有意義!非常感謝! – Adam