'SharpZip'에 해당되는 글 1건

  1. 데이터베이스에서 스토어드 프로시져를 이용하여 테이블을 읽어서 XML파일을 압축하는 코드입니다.

데이터베이스에서 스토어드 프로시져를 이용하여 테이블을 읽어서 XML파일을 압축하는 코드입니다.

ICSharpCode.SharpZipLib.dll을 참조에 추가한다. 자세한 내용은 http://www.sharpdevelop.net/OpenSource/SharpZipLib/Default.aspx을 참조하도록 합니다.

Imports ICSharpCode.SharpZipLib

   ' read path
        Dim savePath As String = String.Empty
        Dim fPath As String = String.Empty
        Dim dataVersion As String = String.Empty
        Dim CRC32 As Checksums.Crc32 = Nothing
        Dim zipOut As Zip.ZipOutputStream = Nothing
        Dim zipEntry As Zip.ZipEntry = Nothing
        Try
            savePath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings("sizer.savePath"))
            fPath = System.IO.Path.Combine(savePath, DatafileFileName)
            Try
                Dim ds As New DataSet("PAXDataSet")
                ds.Namespace = "http://tempuri.org/PAXDataSet.xsd"
                Dim adapt As New SqlClient.SqlDataAdapter("스토어드 프로시져", ConfigurationManager.ConnectionStrings("PAXConnectionString").ConnectionString)
                adapt.Fill(ds)

               '  'Table'테이블에서 각 테이블의 이름을 가져와서 이를 맵핑시킨다.
                For Each row As DataRow In ds.Tables("Table").Rows
                    If ds.Tables(row("SourceTable").ToString) IsNot Nothing Then
                        ds.Tables(row("SourceTable").ToString).TableName = row("MappedTable").ToString
                    End If
                Next

                ds.Tables.Remove("Table")
                ds.AcceptChanges()

                If File.Exists(fPath) Then
                    File.SetAttributes(fPath, FileAttributes.Normal)
                End If

                dataVersion = {버전을 넣습니다.}

                Dim data As String = ds.GetXml.Trim
                Dim buffer() As Byte = System.Text.Encoding.UTF8.GetBytes(data)

                zipOut = New SharpZip.Zip.ZipOutputStream(File.Create(fPath))
                zipOut.SetLevel(9)
                zipOut.SetComment(dataVersion)
                zipOut.Password = {패스워드}
                CRC32 = New Checksums.Crc32
                zipEntry = New Zip.ZipEntry({파일명})
                zipEntry.CompressionMethod = ICSharpCode.SharpZipLib.Zip.CompressionMethod.Deflated
                zipEntry.Comment = dataVersion
                CRC32.Reset()
                CRC32.Update(buffer)
                zipEntry.Crc = CRC32.Value
                zipEntry.DateTime = DateTime.Now
                zipEntry.Size = buffer.Length
                zipOut.PutNextEntry(zipEntry)
                zipOut.Write(buffer, 0, buffer.Length)
                zipOut.Flush()
            Finally
                If zipOut IsNot Nothing Then
                    Try
                        zipOut.Finish()
                        zipOut.Close()
                        zipOut.Dispose()
                    Catch : End Try
                End If
            End Try
        Catch ex As Exception
            [Throw Exception...]
        End Try