C # Use WinRAR (encrypted) to compress and decompress related folders and files

Source: Internet
Author: User

the main implementation of this example:
1. compressing folders and their files
2. compressing files in a folder
3. the compressed folder and its files are RAR or zip
4. decompress
5.
-----------
example Code :
protected void button#click (Object sender, eventargs e)
{< br> string strtxtpath = "C :\\ freezip \ free.txt";
string strzippath = "C: \ freezip \ free.zip ";
system. diagnostics. process process1 = new system. diagnostics. process ();
process1.startinfo. filename = "winrar.exe";
process1.startinfo. createnowindow = true;

/// 1
/// Compress c: \ freezip \ free.txt (that is, the folder and its files freezip \ free.txt)
/// To c: \ freezip \ free.rar
// Strzippath = "C: \ freezip \ free"; // The default compression mode is. rar.
// Process1.startinfo. Arguments = "a-r" + strzippath + "" + strtxtpath;

/// 2
/// Compress c: \ freezip \ free.txt (that is, the folder and its files freezip \ free.txt)
/// To c: \ freezip \ free.rar
// Strzippath = "C: \ freezip \ free"; // set the compression mode to. Zip.
// Process1.startinfo. Arguments = "a-afzip" + strzippath + "" + strtxtpath;

/// 3
/// Compress c: \ freezip \ free.txt (that is, the folder and its files freezip \ free.txt)
/// Directly set free.zip to c: \ freezip \ free.zip.
// Process1.startinfo. Arguments = "a-r" + strzippath + "" + strtxtpath;

/// 4
/// Migrate and compress c: \ freezip \ free.txt (that is, the folder and its files freezip \ free.txt)
/// To c: \ freezip \ free.rar after compression, the original file will not exist
// Process1.startinfo. Arguments = "M" + strzippath + "" + strtxtpath;

/// 5
/// Compress free.txt(file free.txt) in c: \ freezip)
/// To c: \ freezip \ free.zip, set it to free.zip. Only files are available, but no folders are available.
// Process1.startinfo. Arguments = "a-EP" + strzippath + "" + strtxtpath;

/// 6
/// Decompress c: \ freezip \ free.rar
/// To c: \ freezip \
// Strtxtpath = "C :\\ freezip \\";
// Process1.startinfo. Arguments = "X" + strzippath + "" + strtxtpath;

/// 7
/// Encrypted compression c: \ freezip \ free.txt (that is, the folder and its files freezip \ free.txt)
/// The password for connecting to c: \ freezip \ free.zip is 123456. Note that no space is allowed between parameters.
// Process1.startinfo. Arguments = "a-p123456" + strzippath + "" + strtxtpath;

/// 8
/// Decompress the encrypted c: \ freezip \ free.rar
/// To c: \ freezip \ Password is 123456. Do not set spaces between parameters.
// Strtxtpath = "C :\\ freezip \\";
// Process1.startinfo. Arguments = "X-p123456" + strzippath + "" + strtxtpath;

/// 9
////-O + overwrite existing files
///-O-Do Not Overwrite existing files
// Strtxtpath = "C :\\ freezip \\";
// Process1.startinfo. Arguments = "X-O +" + strzippath + "" + strtxtpath;

/// 10
/// Only from the specified zip
//// Decompress free1.txt
//// Go to the specified path
/// Other files in the compressed package are not decompressed.
// Strtxtpath = "C :\\ freezip \\";
// Process1.startinfo. Arguments = "X" + strzippath + "" + "free1.txt" + "" + strtxtpath;

/// 11
/// Use-y to respond to all requests as "yes" so that the WinRAR window is not displayed even if an error occurs.
///-Cl converts the file name to lowercase letters.
// Strtxtpath = "C :\\ freezip \\";
// Process1.startinfo. Arguments = "T-y-Cl" + strzippath + "" + "free1.txt ";

Process1.start ();
If (process1.hasexited)
{
Int iexitcode = process1.exitcode;
If (iexitcode = 0)
{
Response. Write (iexitcode. tostring () + "normal completion ");
}
Else
{
Response. Write (iexitcode. tostring () + "incorrect completion ");
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.