Decompress RAR and use unrar. dll C #

Source: Internet
Author: User
Extract RAR and use unrar. dll
The solution we often see is to use process to call WinRAR for decompression, but the server does not necessarily have to buy WinRAR. To call process, you must have sufficient permissions for the Internet account set by IIS? Another solution is to use unrar. dll.

After unrar is downloaded and unrar is unlocked, it contains examples of C # language. After reading license.txt, it should be applicable to commercial activities.

「 May be used in any software to handle RAR archives without limitations free of charge 」

I tried to use it in the Web site project. The document name can also be properly unlocked. But it should be noted that unrar. DLL is not native. net DLL, but written in C ++, which provides unrar. CS uses C # To package a layer and uses dllimport to call its functions. Therefore, you do not need to add a reference in the project. You can directly copy the content to the bin directory, in addition, it does not work on the web server in the development environment (the DLL cannot be read) and can be placed on IIS.

It's really easy to use. The code is like this.

Using System;
Using System. IO;
Using Schematrix;

Public   Partial   Class _ Default: system. Web. UI. Page {
Protected   Void Page_load ( Object Sender, eventargs e ){
String File = Server. mappath ( " ~ /App_data/image .rar " );
String Targetpath = Server. mappath ( " ~ /App_data/ " );
Decompressrar (file, targetpath, False );
}

Public   Void Decompressrar ( String Rararchive, String Destinationpath, Bool Createdir ){
If (File. exists (rararchive )){
Unrar =   New Unrar (rararchive );
Unrar. Open (unrar. openmode. Extract );
Unrar. destinationpath = Destinationpath;

While (Unrar. readheader ()){
If (Unrar. currentfile. isdirectory ){
Unrar. Skip ();
} Else {
If (Createdir ){
Unrar. Extract ();
} Else {
Unrar. Extract (destinationpath + Path. getfilename (unrar. currentfile. filename ));
}
}
}
Unrar. Close ();
}
}
}

Download the entire example (it can only be executed on IIS)

 

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.