Clean filename for temp files, centralize windream basepath
This commit is contained in:
@@ -4,34 +4,35 @@ Imports Microsoft.Office.Interop
|
||||
|
||||
|
||||
Public Class ClassFileDrop
|
||||
Public Shared files_dropped As String()
|
||||
'Public Shared Property FilesDropped As String()
|
||||
|
||||
Public Shared Property FilesDropped As New List(Of String)
|
||||
|
||||
' Tobit David Drag Drop: https://www.david-forum.de/thread/12671-drag-and-drop-von-faxen-und-mails-in-net-anwendung/
|
||||
'Private Declare Function DVEmlFromMailItem Lib "DvApi32" (ByVal oMailItem As MailItem, ByVal strFileName As String) As Long
|
||||
|
||||
Public Shared Function Drop_File(e As DragEventArgs)
|
||||
Try
|
||||
LOGGER.Debug("Available Drop Formats:")
|
||||
|
||||
For Each oFormat As String In e.Data.GetFormats()
|
||||
LOGGER.Debug(oFormat)
|
||||
Next
|
||||
|
||||
LOGGER.Info("Drop_File")
|
||||
files_dropped = Nothing
|
||||
|
||||
FilesDropped.Clear()
|
||||
|
||||
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
|
||||
Dim MyFiles() As String
|
||||
Dim i As Integer
|
||||
Dim oFilesFromEvent() As String
|
||||
Dim oIndex As Integer
|
||||
' Assign the files to an array.
|
||||
MyFiles = e.Data.GetData(DataFormats.FileDrop)
|
||||
oFilesFromEvent = e.Data.GetData(DataFormats.FileDrop)
|
||||
' Loop through the array and add the files to the list.
|
||||
For i = 0 To MyFiles.Length - 1
|
||||
LOGGER.Info("Simple FileDrop - File: " & MyFiles(i))
|
||||
ReDim Preserve files_dropped(i)
|
||||
files_dropped(i) = "|DROPFROMFSYSTEM|" & MyFiles(i)
|
||||
For oIndex = 0 To oFilesFromEvent.Length - 1
|
||||
LOGGER.Info("Simple FileDrop - File: " & oFilesFromEvent(oIndex))
|
||||
FilesDropped.Add("|DROPFROMFSYSTEM|" & oFilesFromEvent(oIndex))
|
||||
|
||||
'ReDim Preserve FilesDropped(oIndex)
|
||||
'FilesDropped(oIndex) = "|DROPFROMFSYSTEM|" & oFilesFromEvent(oIndex)
|
||||
' ListBox1.Items.Add(MyFiles(i))
|
||||
Next
|
||||
Return True
|
||||
|
||||
ElseIf (e.Data.GetDataPresent("FileGroupDescriptor")) AndAlso (e.Data.GetDataPresent("FileContents")) Then
|
||||
'// the first step here is to get the stbFileName
|
||||
'// of the attachment and
|
||||
@@ -40,9 +41,9 @@ Public Class ClassFileDrop
|
||||
'//
|
||||
'// set up to obtain the aryFileGroupDescriptor
|
||||
'// and extract the file name
|
||||
Dim stmInput As IO.Stream = CType(e.Data.GetData("FileGroupDescriptor"), IO.Stream)
|
||||
Dim oStream As IO.Stream = CType(e.Data.GetData("FileGroupDescriptor"), IO.Stream)
|
||||
Dim aryFileGroupDescriptor(512) As Byte ' = new byte[512]
|
||||
stmInput.Read(aryFileGroupDescriptor, 0, 512)
|
||||
oStream.Read(aryFileGroupDescriptor, 0, 512)
|
||||
'// used to build the stbFileName from the aryFileGroupDescriptor block
|
||||
Dim stbFileName As System.Text.StringBuilder = New System.Text.StringBuilder("")
|
||||
'// this trick gets the stbFileName of the passed attached file
|
||||
@@ -51,13 +52,11 @@ Public Class ClassFileDrop
|
||||
stbFileName.Append(Convert.ToChar(aryFileGroupDescriptor(intCnt), System.Globalization.CultureInfo.CreateSpecificCulture("de-DE")))
|
||||
intCnt += 1
|
||||
Loop
|
||||
stmInput.Close()
|
||||
oStream.Close()
|
||||
'Sonderzeichen entfernen
|
||||
Dim Tempfilename = DigitalData.Modules.Language.Utils.RemoveInvalidCharacters(stbFileName.ToString)
|
||||
Dim anhaenge = e.Data.GetDataPresent("FileContents")
|
||||
'Dim path As String = "C:\VBProjekte\Dateien"
|
||||
'// put the zip file into the temp directory
|
||||
Dim strOutFile As String = Path.GetTempPath() & Tempfilename
|
||||
Dim oTempFileName = DigitalData.Modules.Language.Utils.RemoveInvalidCharacters(stbFileName.ToString)
|
||||
Dim oAttachments = e.Data.GetDataPresent("FileContents")
|
||||
Dim strOutFile As String = Path.Combine(Path.GetTempPath(), oTempFileName)
|
||||
'// create the full-path name
|
||||
'//
|
||||
'// Second step: we have the file name.
|
||||
@@ -65,13 +64,13 @@ Public Class ClassFileDrop
|
||||
'// data for the attached file and copy it to disk so we work on it.
|
||||
'//
|
||||
'// get the actual raw file into memory
|
||||
Dim msInput As IO.MemoryStream = CType(e.Data.GetData("FileContents", True), IO.MemoryStream) 'This returns nothing for an Email
|
||||
If msInput Is Nothing = False Then
|
||||
Dim oMemoryStreamInput As IO.MemoryStream = CType(e.Data.GetData("FileContents", True), IO.MemoryStream) 'This returns nothing for an Email
|
||||
If oMemoryStreamInput Is Nothing = False Then
|
||||
'// allocate enough bytes to hold the raw date
|
||||
Dim aryFileBytes(CType(msInput.Length, Int32)) As Byte
|
||||
Dim aryFileBytes(CType(oMemoryStreamInput.Length, Int32)) As Byte
|
||||
'// set starting position at first byte and read in the raw data
|
||||
msInput.Position = 0
|
||||
msInput.Read(aryFileBytes, 0, CType(msInput.Length, Int32))
|
||||
oMemoryStreamInput.Position = 0
|
||||
oMemoryStreamInput.Read(aryFileBytes, 0, CType(oMemoryStreamInput.Length, Int32))
|
||||
'// create a file and save the raw zip file to it
|
||||
Dim fsOutput As IO.FileStream = New IO.FileStream(strOutFile, IO.FileMode.Create) ';
|
||||
fsOutput.Write(aryFileBytes, 0, aryFileBytes.Length)
|
||||
@@ -83,9 +82,12 @@ Public Class ClassFileDrop
|
||||
Dim finTemp As IO.FileInfo = New IO.FileInfo(strOutFile)
|
||||
'// always good to make sure we actually created the file
|
||||
If (finTemp.Exists = True) Then
|
||||
ReDim Preserve files_dropped(0)
|
||||
files_dropped(0) = "|OUTLOOK_ATTACHMENT|" & strOutFile
|
||||
LOGGER.Info("Drop an Attachment - File: " & strOutFile)
|
||||
FilesDropped.Add("|OUTLOOK_ATTACHMENT|" & strOutFile)
|
||||
|
||||
'ReDim Preserve FilesDropped(0)
|
||||
'FilesDropped(0) = "|OUTLOOK_ATTACHMENT|" & strOutFile
|
||||
|
||||
Return True
|
||||
Else
|
||||
LOGGER.Info("Attachment File from Outlook could not be created")
|
||||
@@ -111,12 +113,6 @@ Public Class ClassFileDrop
|
||||
If subj = "" Then
|
||||
subj = "NO_SUBJECT"
|
||||
End If
|
||||
If subj.Contains("\") Then
|
||||
subj = subj.Replace("\", "-")
|
||||
End If
|
||||
If subj.Contains("/") Then
|
||||
subj = subj.Replace("/", "-")
|
||||
End If
|
||||
|
||||
'Sonderzeichen entfernen
|
||||
subj = DigitalData.Modules.Language.Utils.RemoveInvalidCharacters(subj)
|
||||
@@ -138,8 +134,10 @@ Public Class ClassFileDrop
|
||||
"Weitere Informationen finden Sie im Log.", MsgBoxStyle.Critical, "Global Indexer")
|
||||
End Try
|
||||
|
||||
ReDim Preserve files_dropped(i)
|
||||
files_dropped(i) = "|OUTLOOK_MESSAGE|" & oFilename
|
||||
FilesDropped.Add("|OUTLOOK_MESSAGE|" & oFilename)
|
||||
|
||||
'ReDim Preserve FilesDropped(i)
|
||||
'FilesDropped(i) = "|OUTLOOK_MESSAGE|" & oFilename
|
||||
Next
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user