无效的RarHeader:使用SharpCompress Package在c#中使用16

时间:2018-03-13 10:00:29

标签: c# 7zip rar sevenzipsharp sharpcompress

我在使用sharpcompress包在c#中提取rar文件时遇到错误,我在Nunrar,sevenzip提取器和很多软件包中尝试过,但面临同样的错误

String filename = @"" + textBox8.Text;
string ppath = @"" + System.IO.Path.GetDirectoryName(textBox8.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(textBox8.Text);
System.IO.Directory.CreateDirectory(@"" + ppath);
try
{
    var archive = SharpCompress.Archives.Rar.RarArchive.Open(filename);
    foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
    {
        entry.WriteToDirectory(ppath, new ExtractionOptions()
        {

        });
    }
}
catch(Exception ex)
{
    textBox10.Text = Convert.ToString(ex);
}

1 个答案:

答案 0 :(得分:0)

最后我解决了NunRar支持Rar4格式

String filename = @"" + textBox8.Text;             string ppath = @"" + System.IO.Path.GetDirectoryName(textBox8.Text)+" \" + System.IO.Path.GetFileNameWithoutExtension(textBox8.Text);             string ext = textBox7.Text.Substring(textBox7.Text.IndexOf("。"));

            try
            {


                if (ext == ".rar")
                {
                    System.IO.Directory.CreateDirectory(@"" + ppath);
                    try
                    {
                        NUnrar.Archive.RarArchive.WriteToDirectory(filename, ppath, NUnrar.Common.ExtractOptions.ExtractFullPath | NUnrar.Common.ExtractOptions.Overwrite);

                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);

                    }

                }
                else if (ext == ".zip")
                {
                    System.IO.Directory.CreateDirectory(@"" + ppath);
                    try
                    {
                        ZipFile.ExtractToDirectory(filename, ppath);

                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }

                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }