Reputation: 1
I wanted to create a zip file with the code below in Visual Studio 2010 with .NET Framework version 4.0.30319 SP1Rel. I am running this on a Windows XP Pro SP3.
System.IO.Compression.ZipFile.CreateFromDirectory("C:\TargetFolder", "C:\destination.zip")
Initially there was an error as the class Compression.ZipFile was missing. After checking online, I've done 'Add Reference' for Compression, Compression.FileSystem & Compression.ZipFile. So, later, there is no error when compile/Build.
When I run the program and execute the command, the error below appears.
The type initializer for 'System.IO.Compression.Zipfile' threw an exception. at System.IO.Compression.ZipFile.CreateFromDirectory(String sourceDirectoryName, String destinationArchiveFileName)
I then tried the same code on Visual Studio 2010 with .NET Framework version 4.8.04084 SP1Rel and not such error occur. Please help.
Upvotes: 0
Views: 800
Reputation: 180
It required framework 4.5 and above . If you want zip files in .net framework 4.0 then use shell. This might be useful to you https://www.codeproject.com/Tips/257193/Easily-Zip-Unzip-Files-using-Windows-Shell
Upvotes: 0
Reputation: 54457
Given that the ZipFile
class was not introduced until .NET Framework 4.5, as per the documentation, any application targeting an earlier version will not be able to use it.
Upvotes: 0