2011年2月16日 星期三

ASP.NET 網站檔案打包 壓縮 下載

http://dotnetzip.codeplex.com/ 下載檔案
並參照引用 DotNetZipLib-DevKit-v1.9.zip\DotNetZip-v1.9\Release\Ionic.Zip.dll
Imports Ionic.Zip
If (IO.Directory.Exists(Server.MapPath("~\Photo_Package\" + DropDownList1.SelectedItem.Text))) Then
IO.Directory.Delete(Server.MapPath("~\Photo_Package\" + DropDownList1.SelectedItem.Text), True)
End If
IO.Directory.CreateDirectory(Server.MapPath("~\Photo_Package\" + DropDownList1.SelectedItem.Text))
Dim scrpath As String = Server.MapPath("~\File_Save\")
Dim dstpath As String = Server.MapPath("~\Photo_Package\" + DropDownList1.SelectedItem.Text + "\")
File.Copy(scrpath + '檔名', dstpath + Replace(Replace('檔名', "\", ""), "/", "") + ".JPG", True)
Dim files() As String = Directory.GetFiles(Server.MapPath("~\Photo_Package\" + DropDownList1.SelectedItem.Text))
Using zip As New ZipFile(System.Text.Encoding.Default)'中文問題
For Each s As String In files
zip.AddFile(s, DropDownList1.SelectedItem.Text)
Next
zip.Save(Server.MapPath("~\Photo_Package\" + DropDownList1.SelectedItem.Text + ".zip"))
End Using