You can easily extract the contents of a ZIP file on the server by following the steps given below.
Please note that in order to work with the example you should install XCeed ZIP for .NET which is available for download (45 days trial) from http://xceed.com/Zip_Net_Whatsnew.html
Step - 1
Copy the following DLL's to the BIN directory of your website. If there is no such directory, then you can create it
Xceed.Compression.dll
Xceed.Compression.Formats.dll
Xceed.FileSystem.dll
Xceed.Zip.dll
You can locate these DLL files from Program Files\Xceed Components\Bin\.NET folder
Step - 2
Add the following code to the Page_Load() event
Try
Xceed.Zip.Licenser.LicenseKey = "ZINXX-XXXXX-XXXXX-XXXX"
Dim zip As New ZipArchive(New DiskFile(Server.MapPath(".") & "\Test.zip"))
Dim folder As New DiskFolder(Server.MapPath("."))
zip.CopyFilesTo(folder, True, True)
Response.Write("Files Unzipped Successfully")
Catch err As Exception
Response.Write(err.Message)
Finally
End Try
That's it. Execute the file and you will see a message "Files Unzipped Successfully". You should see a new folder named Test with the required file inside the root of your domain.
Please make sure to upload Test.Zip into the root directory before attempting to run the above code.
Regards,
Anand
Author:
Community Server Quickly - Packt Publishing