Question

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; 
}
Was it helpful?

Solution

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.

OTHER TIPS

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);
   }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top