Create and protect a zip archive with a password¶
This page covers how to create, extract and protect a zip archive with a password.
Nella libreria dei template, sotto la sezione Scripts, è disponibile l’oggetto ZipUnzipLogic che consente di creare/scompattare archivi. Dispone dei metodi esportati CreateZipArchive
, per creare un file zip e UnzipArchive
per scompattare i contenuti di un file zip. L’oggetto dispone delle seguenti proprietà:
Source
: when running theCreateZipArchive
method, it indicates the full path to files or folder to be compressed. However, when runningUnzipArchive
, it indicates the path to the zip file to be extracted.Target
: when running theCreateZipArchive
method, it indicates the full path to the zip file in which compressed files/folders are placed. However, when runningUnzipArchive
, it indicates the destination folder in which extracted items are placed.Password
: Optional parameter. Indicates the password to be used to extract or compress files.
Importing the script in a project
Lo script utilizza la libreria SharpZipLib che permette di comprimere, decomprimere file zip e proteggerli eventualmente con una password. Una volta importato lo script nel progetto, è necessario eseguire i seguenti passi affinché la soluzione .NET possa essere compilata correttamente:
Open the .NET solution of your project:
Open the NuGet package manager ( in Visual Studio: Tools > NuGet package manager > Manage NuGet packages for Solution)
In the Browse section, find the
SharpZipLib
and proceed with the installation.Double click the project’s
.csproj
and add the following line:<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
after<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
Rebuild the solution
To use the script, the CreateZipArchive and UnzipArchive methods must be invoked through an event e.g. a MouseClick event of a button.