I want to unzip a file with ZipFile class in c# (VS2012). Even if I copy the paths directly from win explorer I get this error:
System.ArgumentExcepti
As you already know some characters are not valid on windows:
\ / : * ? " < > |
This would bring a lot of situations when your application receives zip from different OS since some of those invalid characters are valid in other OS.
In order to solve this problem you can sanitize your files names before you extract them:
public void ExtractZipFileToPath(
string zipFilePath,
string ouputPath
)
{
using (var zip = ZipFile.Read(zipFilePath))
{
foreach (var entry in zip.Entries.ToList())
{
entry.FileName = SanitizeFileName(entry.FileName);
entry.Extract(ouputPath);
}
}
}
Sanitizing examples here How to remove illegal characters from path and filenames?