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

sloqye picture sloqye · Jan 3, 2014 · Viewed 8.2k times · Source

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

Answer

Roman Pushkin picture Roman Pushkin · Jan 3, 2014

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.