0
我有一個包含多個文件的目錄。我想壓縮此文件夾到一個zip(使用Xceed第三方DLL庫),並通過HTTP推送給用戶。同時,我想創建文件夾內所有文件的日誌,並將其附加到壓縮文件的一部分。使用Xceed在旅途中壓縮目錄
我目前使用DotNetZip和它的工作完美。我需要Xceed中的這個等價物。
下面是一個使用DotNetZip
Imports Ionic.Zip
' Tell the browser we're sending a ZIP file!
Dim downloadFileName As String = String.Format("YourDownload-{0}.zip", DateTime.Now.ToString("yyyy-MM-dd-HH_mm_ss"))
Response.ContentType = "application/zip"
Response.AddHeader("Content-Disposition", "filename=" & downloadFileName)
' Zip the contents of the selected files
Using zip As New ZipFile()
' Construct the contents of the README.txt file that will be included in this ZIP
Dim readMeMessage As String = String.Format("Your ZIP file {0} contains the following files:{1}{1}", downloadFileName, Environment.NewLine)
For i As Integer = 0 To MainDirs.Length - 1
readMeMessage &= String.Concat(vbTab, "* ", MainDirs(i), Environment.NewLine)
' Now add the file to the ZIP (use a value of "" as the second parameter to put the files in the "root" folder)
zip.AddFile(MainDirs(i), "Your Files")
Next
' Add the README.txt file to the ZIP
zip.AddEntry("README.txt", readMeMessage, Encoding.ASCII)
' Send the contents of the ZIP back to the output stream
zip.Save(Response.OutputStream)
End Using
End Sub