现在的位置: 首页 > 综合 > 正文

sharpziplib是一个不错的在线压缩软软件.用VB.net简单写了个使用代码!

2012年05月15日 ⁄ 综合 ⁄ 共 1535字 ⁄ 字号 评论关闭
 1Dim zipname As String = Path.Combine(Me.zipdir, (Me.txtZipFile.Text.ToString & ".zip"))
 2        Dim crc1 As New Crc32
 3        Dim s As ZipOutputStream = New ZipOutputStream(File.Create(zipname))
 4        s.SetLevel(6)
 5        Dim i As Integer
 6        Dim flename As String() = {Server.MapPath("temp\index.htm"), Server.MapPath("temp\regriter.htm")}
 7
 8        For i = 0 To flename.Length - 1
 9            Dim name As String = flename(i)
10            Dim stratem As FileStream = File.OpenRead(name)
11            Dim buffer As Byte() = New Byte(stratem.Length - 1) {}
12            stratem.Read(buffer, 0, buffer.Length)
13            Dim filename1 As String = name.Replace((Me.timpdir & "\"), "")
14            Dim entry As New ZipEntry(filename1)
15            entry.DateTime = DateTime.Now
16            entry.Size = stratem.Length
17            stratem.Close()
18            crc1.Reset()
19            crc1.Update(buffer)
20            entry.Crc = crc1.Value
21            s.PutNextEntry(entry)
22            s.Write(buffer, 0, buffer.Length)
23        Next
24        s.Finish()
25        s.Close()
 1Imports System.IO
 2
 3Public Class util
 4
 5    Public Shared Function GetDirecotry(ByVal DirecotryName As StringAs String
 6        Dim dir As String = HttpContext.Current.Request.PhysicalApplicationPath
 7        dir = Path.Combine(dir, DirecotryName)
 8        If Directory.Exists(dir= True Then
 9            Directory.CreateDirectory(dir)
10        End If
11        Return dir
12    End Function

13
14End Class

抱歉!评论已关闭.