Recently, I made an email sending tool, which has an attachment function,
If the attachment is too large, it is usually compressed by winara sub-volumes and then uploaded.
How can I use a program to implement automatic volume splitting and compression? Because RAR is not free, you can find 7z online.
Install 7z, copy 7z. DLL to the program directory, and reference the DLL sevenzipsharp.
Introduce using sevenzip. SDK. compression;
Using sevenzip; the two namespaces
Code
/// <Summary>
/// Cut the file. When the file size is greater than the capacity of the configuration file, the file is cut.
/// </Summary>
/// <Param name = "filepath"> path of the PDF file under user: EG user/2000/01/01/xxxx.pdf </param>
/// <Param name = "descdecpath"> User, 2000/01, 01, and temp </param>
/// <Returns> </returns>
Public bool splitfile (string filepath, string descdecpath)
{
Fileinfo finfo = new fileinfo (filepath );
String copyfilepath = path. Combine (descdecpath, finfo. Name );
// If (finfo. Length <= This. filesize) return false;
If (! Directory. exists (descdecpath ))
{
Directory. createdirectory (descdecpath );
}
File. Copy (filepath, copyfilepath );
Application. doevents ();
Sevenzipcompressor TMP = new sevenzipcompressor ();
Sevenzipcompressor. setlibrarypath (application. startuppath + "/7z. dll ");
// TMP. volumesize = finfo. Length <= This. filesize? 0: This. filesize;
TMP. volumesize = This. filesize; // volume size. up to 1000 files can be separated.
TMP. archiveformat = outarchiveformat. sevenzip;
TMP. compressdirectory (descdecpath, copyfilepath );
File. Delete (copyfilepath); // Delete the copy object
If (directory. getfiles (descdecpath). Length = 1)
{
Foreach (string path in directory. getfiles (descdecpath ))
{
File. Delete (PATH );
}
TMP. volumesize = 0;
TMP. compressfiles (copyfilepath + ". 7z ",
New String [] {filepath}); // compressed file
}
Application. doevents ();
Return true;
}
Because there is no file sharding compression class library, I would like to perform the second step: Use the folder sharding compression, copy the file to a temporary folder, and then compress the Temporary Folder.
See the Code: