0

I am Facing Error when Extract a rar file in c# using sharpcompress package,i have tried in Nunrar,sevenzip extractor and so many packages,But facing that same error

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);
}
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900

1 Answers1

0

Finally I solved it NunRar Supports Rar4 format

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

            }