如何使用sevenzipsharp一个提取我的档案文件之一 [英] How to extract files in my archive one by one using sevenzipsharp

查看:1044
本文介绍了如何使用sevenzipsharp一个提取我的档案文件之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用此代码:

 公共无效提取物(字符串的SourceFile,字符串密码)
{
SevenZipExtractor szip =新SevenZipExtractor(的SourceFile,密码);
的foreach(的DataGridViewRow行DGVFile.Rows)
{
串NameFile =(字符串)row.Cells [0] .value的;
INT indexZip = szip.ArchiveFileData.IndexOf(NameFile);
流pathDirectory = @C:\\;
szip.ExtractFile(indexZip,pathDirectory);
}
}



但是那错误,在7号线和8也许任何人都可以解释如何得到我的档案索引文件与已经选择在我的DataGridView,也可变pathDirectory文件流的目的名。
谢谢



编辑:
我使用的DataGridView DGVDekripsi,所以我取代了它。这个正确的代码,它的工作原理。

 公共无效提取物(字符串的SourceFile,字符串密码)
{
字符串OutputLocation = txtOutputDe.Text;
SevenZipExtractor szip =新SevenZipExtractor(的SourceFile,密码);
的foreach(的DataGridViewRow行DGVDekripsi.Rows)
{
串NameFile =(字符串)row.Cells [1] .value的;
的FileStream FS = File.OpenWrite(Path.Combine(OutputLocation,NameFile));
szip.ExtractFile(NameFile,FS);
}
的回报;
}


解决方案

8号线(确保使用System.IO; ):

 的FileStream FS = File.OpenWrite( Path.Combine(@C:\,NameFile)); 
szip.ExtractFile(indexZip,FS);

请确保您有权限写入到C盘,或更改临时文件夹的路径。


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

解决方案

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.

这篇关于如何使用sevenzipsharp一个提取我的档案文件之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆