93 lines
3.3 KiB
VB.net
93 lines
3.3 KiB
VB.net
Imports System.IO
|
|
Imports ICSharpCode.SharpZipLib.Zip
|
|
Imports ICSharpCode.SharpZipLib.Tar
|
|
Public Class ZipClass
|
|
|
|
Dim m_zipfilename As String
|
|
Property ZipFileName As String
|
|
Get
|
|
Return m_zipfilename
|
|
End Get
|
|
Set(value As String)
|
|
m_zipfilename = value
|
|
End Set
|
|
End Property
|
|
|
|
Public Sub Extract_Zip(Filename As String, dossiernr As Integer, extractto As String, retfilename As String)
|
|
Dim fastzip As New FastZip
|
|
Dim FileFilter As String = ""
|
|
fastzip.ExtractZip(Filename, extractto, FileFilter)
|
|
Create_Structure(dossiernr, retfilename, extractto)
|
|
|
|
End Sub
|
|
|
|
Private Sub Create_Structure(dossiernr As Integer, retfilename As String, filepath As String)
|
|
FileOpen(1, retfilename, OpenMode.Input)
|
|
Dim s As String
|
|
Dim dt As New DataTable
|
|
Dim RootDirectory As String
|
|
Dim db As New clsDBZugriffe
|
|
Dim Subdirectory_Name As String
|
|
While Not EOF(1)
|
|
Input(1, s)
|
|
Try
|
|
Dim startindex As Integer = s.IndexOf("NRDOK00 = '") + 11
|
|
If startindex < 11 Then startindex = s.IndexOf("NRDOC00 = '") + 11
|
|
Dim endindex As Integer = s.IndexOf("] [-o") - 2 - startindex
|
|
|
|
Dim dokumentid As String = s.Substring(startindex, endindex)
|
|
Dim DestFilename As String = ""
|
|
|
|
startindex = s.IndexOf("[-o ") + 3
|
|
endindex = s.IndexOf("] [-a]") - 0 - startindex
|
|
Dim filename As String = s.Substring(startindex, endindex)
|
|
|
|
|
|
dt = db.Get_Dokumentbezeichnung(dokumentid)
|
|
Dim directoryname As String
|
|
|
|
directoryname = My.Settings.Temp_Folder + "\" + dossiernr.ToString + "_" + dt.Rows(0).Item(3).ToString
|
|
RootDirectory = directoryname
|
|
If System.IO.Directory.Exists(directoryname) Then
|
|
Else
|
|
System.IO.Directory.CreateDirectory(directoryname)
|
|
End If
|
|
Subdirectory_Name = dt.Rows(0).Item(1)
|
|
Subdirectory_Name = Subdirectory_Name.Replace("/", "_")
|
|
directoryname = directoryname + "\" + Subdirectory_Name
|
|
If System.IO.Directory.Exists(directoryname) Then
|
|
Else
|
|
System.IO.Directory.CreateDirectory(directoryname)
|
|
End If
|
|
DestFilename = dt.Rows(0).Item(0).ToString + ".pdf"
|
|
DestFilename = DestFilename.Replace("/", "_")
|
|
DestFilename = DestFilename.Replace("\", "_")
|
|
DestFilename = DestFilename.Replace(":", "_")
|
|
Try
|
|
System.IO.File.Move(filepath + "\" + filename + ".pdf", directoryname + "\" + dt.Rows(0).Item(4).ToString + "_" + DestFilename)
|
|
Catch
|
|
End Try
|
|
Catch ex As Exception
|
|
PrintLog(ex.Message)
|
|
End Try
|
|
|
|
|
|
End While
|
|
FileClose(1)
|
|
|
|
Create_new_zip(RootDirectory)
|
|
End Sub
|
|
|
|
Private Sub Create_new_zip(ByVal Directory As String)
|
|
Dim fastzip As New FastZip
|
|
Dim recurse As Boolean = True
|
|
Dim Filter = ""
|
|
Me.ZipFileName = Directory + ".zip"
|
|
fastzip.CreateZip(Me.ZipFileName, Directory, recurse, Filter)
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
End Class
|