How to extract files in my archive one by one using sevenzipsharp

给你一囗甜甜゛ 提交于 2019-12-23 05:27:22

问题


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. Thanks

Edit: i use DataGridView DGVDekripsi, so i replaced it. 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; 
}

回答1:


Line 8 (make sure 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.




回答2:


IndexOf() not works for me... I love this solution:

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


来源:https://stackoverflow.com/questions/20898794/how-to-extract-files-in-my-archive-one-by-one-using-sevenzipsharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!