// instantiate a file selection dialog
OpenFileDialog ofd = new OpenFileDialog ();
// File Filter | number is in front of posters, followed by the computer to see
ofd.Filter = "text document (* .txt) | * .txt | * * | * *..";
// Get the directory of the file to be compressed, this directory may be re-generated using the compressed packet
string fileBasePath = Path.GetDirectoryName (file path);
After the removal of the file name extension // get the file you want to compress the
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension (textBox1.Text.Trim () );
// zip compressed file name
string zipFileName = fileNameWithoutExtension + ".zip" ;
// zip file storage address, i.e. full path
string zipFilrePath = Path.Combine (fileBasePath, zipFileName );
// Create a compressed packet (corresponding to create a project)
the using (= ZipFile.Create the ZipFile ZipFile (zipFilrePath))
{
// begin update archive (corresponding to open the box)
zipfile.BeginUpdate ();
// compression package Add a file
zipfile.Add (textBox1.Text.Trim (), Path.GetFileName (textBox1.Text.Trim ()));
// submit updated
zipfile.CommitUpdate ();
}
----------------------------------unzip
// instantiate a file selection dialog box
the OpenFileDialog new new the OpenFileDialog the OFD = ();
// File Filter
ofd.Filter = "compressed file (* .zip) | * .zip" ;
// Select the directory address unzipped
FolderBrowserDialog fbd = new FolderBrowserDialog();
string selectedPath = fbd.SelectedPath; // get selected folder path
// decompression method
bool ret = this.Decompress(zipFileName, descFilePath);