close
最近剛好有需要用到壓縮方式
當然第一件就是google一下人家怎麼做的啦
最後還是想到用7-zip(因為是freeware)
寫了一個簡單的壓縮方式
首先當然是要去抓7-zip的軟體啦
下載位址:http://www.7-zip.org/download.html
接著把7za.exe放到自已的專案裡面
然後就是程式碼了....
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click '參數一:要壓縮的檔名 '參數二:要壓縮的檔案 SevenZip("c:\test.zip", "c:\test\*.*", "") End Sub Public Sub SevenZip(ByVal ZipFileName, ByVal ZipSourcePath, ByVal ZipPassWord) Dim ZipPs As New Diagnostics.Process Try Dim strExec As String = Server.MapPath("7z/7za.exe") Dim strAgr As String '需要設定密碼 If ZipPassWord <> "" Then strAgr = "a " & ZipFileName & " " & ZipSourcePath & " -p" & ZipPassWord Else '不需要密碼 strAgr = "a " & ZipFileName & " " & ZipSourcePath & "" End If ZipPs.StartInfo.FileName = strExec ZipPs.StartInfo.Arguments = strAgr ZipPs.StartInfo.WindowStyle = Diagnostics.ProcessWindowStyle.Normal ZipPs.Start() ZipPs.WaitForExit() ZipPs.Close() If Dir(ZipFileName) <> "" Then Response.Write("Zip Complete.") 'check zip file complete End If Catch ex As Exception Response.Write(ex.Message) End Try End Sub
全站熱搜
留言列表