Checking whether an archive is password-protected in Sevenzipsharp (C#)

1.4k views Asked by At

I'm writing an window form similar to 7-Zip, my problem is in the extraction part, I don't know how to check if the archive I want to extract is password protected or not. Any idea?

2

There are 2 answers

0
carryall On BEST ANSWER

I've got the solution: just check the extractor before extracting the archive:

if (fileExtractor.Check())
{
   fileExtractor.BeginExtractArchive(destination_dir);
}

Doing it this way the fileExtractor.Check() will be false, if the archive requires a password, and you're not providing the password for it or the password is not correct.

0
John Weldon On

It depends on the archive type. The ZIP specification describes how it's done for ZIP, although it's not very robust apparently.