Add My ExportFile function
This commit is contained in:
parent
c1dc7fcc22
commit
d7a4a4441d
@ -1101,6 +1101,69 @@ Public Class Windream2
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function ExportFile(WMObject As WMObject, ExportPath As String) As Boolean
|
||||
Try
|
||||
Dim oWMObject As IWMObject6 = DirectCast(WMObject, IWMObject6)
|
||||
|
||||
Dim oFilenameFull As String = oWMObject.aName
|
||||
Dim oFilenameExport As String
|
||||
Dim oSplitIndex = oFilenameFull.LastIndexOf(".")
|
||||
Dim oVersion = 1
|
||||
|
||||
Dim oFilename = oFilenameFull.Substring(0, oSplitIndex)
|
||||
Dim oExtension = oFilenameFull.Substring(oSplitIndex)
|
||||
|
||||
_logger.Debug("Preparing export of file {0}..", oFilenameFull)
|
||||
_logger.Debug("Filename: {0}", oFilename)
|
||||
_logger.Debug("Extension: {0}", oExtension)
|
||||
|
||||
' build the file path in case the exported file doesn't already exist
|
||||
oFilenameExport = BuildExportPath(ExportPath, oFilename, oExtension)
|
||||
|
||||
' Add version until we find the version that does NOT exist
|
||||
Do While File.Exists(oFilenameExport)
|
||||
oVersion += 1
|
||||
oFilenameExport = BuildExportPath(ExportPath, oFilename, oExtension, oVersion)
|
||||
Loop
|
||||
|
||||
_logger.Debug("File will be exported to {0}", oFilenameExport)
|
||||
|
||||
_logger.Debug("Opening file stream..")
|
||||
Dim oStream As WMStream = oWMObject.OpenStream("BinaryObject", WMObjectStreamOpenMode.WMObjectStreamOpenModeRead)
|
||||
Dim oWMFileIO As New WMFileIO() With {
|
||||
.aWMStreamEx = oStream,
|
||||
.aWMStream = oStream,
|
||||
.bstrOriginalFileName = oFilenameExport
|
||||
}
|
||||
|
||||
_logger.Debug("Exporting file..")
|
||||
oWMFileIO.ExportOriginal(True)
|
||||
|
||||
_logger.Debug("Cleaning up..")
|
||||
oStream.Flush()
|
||||
oStream.Close()
|
||||
|
||||
_logger.Debug("File exported to {0}", oFilenameExport)
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function BuildExportPath(BasePath As String, FilenameWithoutExtension As String, Extension As String, Optional Version As Integer = 1)
|
||||
Dim oFilename
|
||||
|
||||
If Version = 1 Then
|
||||
oFilename = FilenameWithoutExtension & Extension
|
||||
Else
|
||||
oFilename = FilenameWithoutExtension & "_" & Version & Extension
|
||||
End If
|
||||
|
||||
Return Path.Combine(BasePath, oFilename)
|
||||
End Function
|
||||
|
||||
Public Function Export_WMFile(WMPath As String, Exportpath As String)
|
||||
Try
|
||||
If Not Exportpath.EndsWith("\") Then
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user