Use WinRAR in C # to encrypt and compress files

Source: Internet
Author: User

Use WinRAR in C # to encrypt and compress files

This example mainly implements:

1. compress the folder and its files

2. compress files in a folder

3. the compressed folder and its files are rar or zip

4. Extract

5. Encrypted compression and unencrypted Compression

-----------

The sample code is as follows:

?

Protected void button#click (object sender, EventArgs e)

{

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 c:/freezip/free.txt(file free.txt)

/// 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 required between parameters.

// Process1.StartInfo. Arguments = "a-p123456" + strzipPath + "" + strtxtPath;

/// 8

//// Decompress the encrypted c:/freezip/free.rar

//// To c:/freezip/the password is 123456. Do not set spaces between parameters.

// StrtxtPath = "c: // freezip //";

// Process1.StartInfo. Arguments = "x-p123456" + strzipPath + "" + strtxtPath;

Process1.Start ();

If (Process1.HasExited)

{

Response. Write ("finished ");

}

}

# Re: C # (encrypted) compression and decompression of related folders and files

More WinRAR commands (refer to WinRAR help document)

A. Add the file to the compressed file.

C. Add a compressed file comment.

D. delete the file from the compressed file.

E. Extract and compress the compressed file and ignore the path.

F. Refresh the files in the compressed file.

I search for strings in the compressed file

K. Lock the compressed file

M move files and folders to compressed files

R repairs damaged compressed files

Rc rebuild the lost volume

Rn rename the compressed file

Rr [N] add data recovery records

Rv [N] Create recovery volume

S [name] converts a compressed file to a self-extracting file type

S-delete the self-extract Module

T test compressed files

U updates files from compressed files

X decompress the compressed file with the full path name to reply to more comments

# Re: C # (encrypted) compression and decompression of related folders and files

For more information, see WinRAR help documentation)

-Ac clears archive attributes after compression or decompression

-Ad attaches the compressed file name to the target path.

-Af <type> specifies the compressed file format

-Ag [format]: Generate compressed file names on the current date

-Added the archive attribute setting to ao.

-Ap: set the path of the internal compressed file

-As: Synchronized compressed file content

-Av application user identity verification information

-Av-Disable adding user identity verification information

-Cfg-ignore the default configuration and Environment Variables

-Cl converts a file name to lowercase.

-Cu converts a file name to uppercase

-Delete compressed files after df Compression

-Dh: Open the Shared File

-Ds unordered compressed files

-Ed: no empty folder is added.

-En: do not add the "compressed file end" Block

-Ep: exclude paths from names

-Exclude the main folder from the name of ep1

-Expand ep2 to the complete path

-Ep3: extend the full path containing the drive letter

-E [+] <attribute> sets file exclusion and inclusion attributes

-F refresh the file

-Hp [Password] encrypts file data and headers

-Ibck runs WinRAR in the background

-Ieml uses E-mail to send compressed files

-Iicon <Name> specifies the self-extracting icon

-Iimg <Name> specifies the self-extracting image

-Ilog [name] records errors to files

-Inul: Disable the error message.

-Ioff power off the PC

-K: Lock the compressed file

-Kb: retained the decompressed files.

-M Set compression Mode

-Mc <parameter> set advanced Compression Parameters

-Md Select dictionary size

-Ms: Specifies the file storage

-N <File> only contains the specified file

-N @ <list File> use the specified list file to include the file

-OS stores NTFS data streams

-Oc: Set the NTFS "compression" attribute

-Ow processes file user identity verification information

-O + overwrites existing files

-O-Do Not Overwrite existing files

-P [Password] Set Password

-R: Return subfolders

-R0: Only subfolders matching Wildcards are returned.

-Ri: set priority and sleep time

-Rr [N]: add data recovery records

-Rv [N] Create a recovery volume

-S: create a solid compressed file

-S Create a solid group with the number of files

-Se: create a solid group with the file extension

-Sfx [name]: Create a self-extracting File

-Sv: create a solid compressed file that is independent of each other

-Sv-create mutually dependent solid Compression Files

-S-Disable solid-state Algorithms

-T compressed Test File

-Ta <date> only processes files modified after the specified date

-Tb <date>: Only files modified before the specified date are processed.

-Tk: keep the original compressed file time

-Tl: Set the compression time for the latest file

-Tn <time> processes files later than the specified time

-To <time> process objects older than the specified time

-Ts

-U Update file

-V [K | B | f | m | M | g | G]

-Vd: Clear disk content before creating volume shards and compressing

-Ver file version control

-Vn uses the old-style volume naming rules

-Vp is paused before each volume split compression.

-X <File> exclude specified files

-X @ <file list> use the specified list file to exclude the specified file.

-Y: assume that all the query responses are "yes"

-Z <File> reads comments from compressed files

-- Stop scanning of the switch

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.