简体   繁体   English

如何使用sevenzipsharp一一解压档案中的文件

[英]How to extract files in my archive one by one using sevenzipsharp

I try using this Code : 我尝试使用此代码:

public void Extract(string SourceFile, string password)
{
    SevenZipExtractor szip = new SevenZipExtractor(SourceFile, password);
    foreach (DataGridViewRow row in DGVFile.Rows)
    {
        string NameFile = (string)row.Cells[0].Value;
        int indexZip = szip.ArchiveFileData.IndexOf(NameFile);
        Stream pathDirectory = @"C:\\";
        szip.ExtractFile(indexZip, pathDirectory);
    }
}

But thats Error, in line 7 and 8. Maybe anyone can explain how to get the index file in my archive with the name that has been chosen in my datagridview and also the purpose of the File Stream in variable pathDirectory. 但是,这是错误,在第7行和第8行中。也许任何人都可以解释如何使用在datagridview中选择的名称在我的存档中获取索引文件,以及在变量pathDirectory中使用文件流的目的。 Thanks 谢谢

Edit: i use DataGridView DGVDekripsi, so i replaced it. 编辑:我使用DataGridView DGVDekripsi,所以我替换了它。 This correct code, It works. 这个正确的代码,它的工作原理。

public void Extract(string SourceFile, string password) 
{    
   string OutputLocation = txtOutputDe.Text;
   SevenZipExtractor szip = new SevenZipExtractor(SourceFile, password);
   foreach (DataGridViewRow row in DGVDekripsi.Rows)    
   {
      string NameFile = (string)row.Cells[1].Value;
      FileStream fs = File.OpenWrite(Path.Combine(OutputLocation, NameFile));
      szip.ExtractFile(NameFile, fs );
   }    
   return; 
}

Line 8 (make sure using System.IO; ): 第8行(确保using System.IO; ):

FileStream fs = File.OpenWrite(Path.Combine(@"c:\", NameFile));
szip.ExtractFile(indexZip, fs);

Make sure you have permissions to write to disk C, or change the path to temp folder. 确保您具有写入磁盘C的权限,或将路径更改为temp文件夹。

IndexOf() not works for me... I love this solution: IndexOf()对我不起作用...我喜欢这种解决方案:

using (SevenZipExtractor zip = new SevenZipExtractor(zipFile))
{
   int indexZip = zip.ArchiveFileData.First(archiveFileInfo =>
      archiveFileInfo.FileName.Equals("MyFile.xml")).Index;
   using (FileStream fs = File.OpenWrite(tempFile))
   {
      zip.ExtractFile(indexZip, fs);
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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