Code
/// <Summary>
/// Decompress a RAR file.
/// </Summary>
/// <Param name = "zipfilename"> ZIP file to be decompressed. </Param>
/// <Param name = "extractlocation"> ZIP file. </Param>
/// <Param name = "password"> The password of the ZIP file. </Param>
/// <Param name = "Overwrite"> Whether to overwrite existing files. </Param>
Public Static Void Unzip ( String Zipfilename, String Extractlocation, String Password, Bool Overwrite)
{
# Region Implementation
String Myextractlocation = Extractlocation;
If (Myextractlocation = "" )
{
Myextractlocation = Directory. getcurrentdirectory ();
}
If ( ! Myextractlocation. endswith ( " \\ " ))
{
Myextractlocation = Myextractlocation + " \\ " ;
}
Zipinputstream s = New Zipinputstream (file. openread (zipfilename ));
S. Password = Password;
Zipentry theentry;
While (Theentry = S. getnextentry ()) ! = Null )
{
String Directoryname = "" ;
String Pathtozip = "" ;
Pathtozip = Theentry. Name;
If (Pathtozip ! = "" )
Directoryname = Path. getdirectoryname (pathtozip) + " \\ " ;
String Filename = Path. getfilename (pathtozip );
Directory. createdirectory (myextractlocation + Directoryname );
If (Filename ! = "" )
{
If (File. exists (myextractlocation + Directoryname + Filename) && Overwrite) |
( ! File. exists (myextractlocation + Directoryname + Filename )))
{
Filestream streamwriter = File. Create (myextractlocation + Directoryname + Filename );
Int Size = 2048 ;
Byte [] Data = New Byte [ 2048 ];
While ( True )
{
Size = S. Read (data, 0 , Data. Length );
If (Size > 0 )
Streamwriter. Write (data, 0 , Size );
Else
Break ;
}
Streamwriter. Close ();
}
}
}
S. Close ();
# Endregion
File. Delete (zipfilename );
}