MS Service ZuGferd und Begin GUI
This commit is contained in:
@@ -972,7 +972,120 @@ Public Class Windream2
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Public Function Export_WMFile(WMPath As String, Exportpath As String)
|
||||
Try
|
||||
If Not Exportpath.EndsWith("\") Then
|
||||
Exportpath &= "\"
|
||||
End If
|
||||
|
||||
Dim oWMObject As WMObject = GetFileByPath(WMPath)
|
||||
|
||||
_logger.Debug("Working on file: " & oWMObject.aName)
|
||||
|
||||
|
||||
Dim ExportFileIO = New WMOTOOLLib.WMFileIO ' CreateObject("WMOTOOLLib.WMFileIO") ' New WMOTOOLLib.WMFileIO
|
||||
_logger.Debug("ExportFileIO created...")
|
||||
' Stream Interface bereitstellen
|
||||
oWMObject.LockFor(WMObjectEditModeFileSystem)
|
||||
Try
|
||||
If Not oWMObject.aLocked Then
|
||||
oWMObject.lock()
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
|
||||
Dim oWMStream = oWMObject.OpenStream("BinaryObject", WMObjectEditModeTypedData)
|
||||
'### VERSIONIERUNG ###
|
||||
Dim version As Integer = 2
|
||||
'Dim Stammname As String = System.IO.Path.GetFileNameWithoutExtension(Quelle)
|
||||
Dim Filename = oWMObject.aName.Substring(0, oWMObject.aName.LastIndexOf("."))
|
||||
Dim Extension = oWMObject.aName.Substring(oWMObject.aName.LastIndexOf("."))
|
||||
Dim tempFilename As String = Exportpath & Filename & Extension
|
||||
'Überprüfen ob File existiert
|
||||
Do While IO.File.Exists(tempFilename) = True
|
||||
tempFilename = Exportpath & Filename & "_" & version & Extension
|
||||
version = version + 1
|
||||
Loop
|
||||
_logger.Debug("Exportfilename is: " & tempFilename)
|
||||
' den Dateiinhalt der neuen Datei zuweisen
|
||||
ExportFileIO.aWMStream = oWMStream
|
||||
ExportFileIO.bstrOriginalFileName = tempFilename
|
||||
'Das eigentliche kopieren
|
||||
ExportFileIO.ExportOriginal(True)
|
||||
' close the windream file stream
|
||||
oWMStream.Close()
|
||||
oWMObject.Save()
|
||||
oWMObject.unlock()
|
||||
_logger.Info($"WMFile has been exported to {tempFilename} ")
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Public Function Export_WMFile_DocID(WMPath As String, Exportpath As String, DocId As Integer)
|
||||
Try
|
||||
If Not Exportpath.EndsWith("\") Then
|
||||
Exportpath &= "\"
|
||||
End If
|
||||
|
||||
Dim oWMObject As WMObject = GetFileByPath(WMPath)
|
||||
Try
|
||||
_logger.Info("Working on file: " & oWMObject.aName)
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
_logger.Warn("No object created: " & WMPath)
|
||||
Return False
|
||||
End Try
|
||||
Dim ExportFileIO = New WMOTOOLLib.WMFileIO ' CreateObject("WMOTOOLLib.WMFileIO") ' New WMOTOOLLib.WMFileIO
|
||||
_logger.Debug("ExportFileIO created...")
|
||||
' Stream Interface bereitstellen
|
||||
'Try
|
||||
' oWMObject.LockFor(WMObjectEditModeMoveReadOnly) 'WMObjectEditModeFileSystem)
|
||||
'Catch ex As Exception
|
||||
' If Not oWMObject.aLocked Then
|
||||
' Try
|
||||
' oWMObject.lock()
|
||||
' Catch ex1 As Exception
|
||||
' _logger.Warn($"{ex1.Message} Could not lock document - DocID: {DocId}")
|
||||
' Return False
|
||||
' End Try
|
||||
|
||||
' End If
|
||||
' '_logger.(ex)
|
||||
|
||||
'End Try
|
||||
|
||||
Dim oWMStream = oWMObject.OpenStream("BinaryObject", 1)
|
||||
'### VERSIONIERUNG ###
|
||||
Dim version As Integer = 2
|
||||
Dim Extension = oWMObject.aName.Substring(oWMObject.aName.LastIndexOf("."))
|
||||
Dim tempFilename As String = Exportpath & DocId & Extension
|
||||
'Überprüfen ob File existiert
|
||||
Do While IO.File.Exists(tempFilename) = True
|
||||
tempFilename = Exportpath & DocId & "_" & version & Extension
|
||||
version = version + 1
|
||||
Loop
|
||||
_logger.Debug("Exportfilename is: " & tempFilename)
|
||||
' den Dateiinhalt der neuen Datei zuweisen
|
||||
ExportFileIO.aWMStream = oWMStream
|
||||
ExportFileIO.bstrOriginalFileName = tempFilename
|
||||
'Das eigentliche kopieren
|
||||
ExportFileIO.ExportOriginal(True)
|
||||
' close the windream file stream
|
||||
oWMStream.Close()
|
||||
_logger.Info($"WMFile DocID {DocId} has been exported to {tempFilename} ")
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
_logger.Info("Unexpected error in Export_WMFile: " & ex.Message)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Public Function TestFolderExists(Path As String) As Boolean
|
||||
Return TestObjectExists(GetNormalizedPath(Path), WMEntityFolder)
|
||||
End Function
|
||||
|
||||
Reference in New Issue
Block a user