fix file access error and illegal path error
This commit is contained in:
@@ -41,20 +41,26 @@ Public Class ClassFileDrop
|
||||
'//
|
||||
'// set up to obtain the aryFileGroupDescriptor
|
||||
'// and extract the file name
|
||||
Dim oStream As IO.Stream = CType(e.Data.GetData("FileGroupDescriptor"), IO.Stream)
|
||||
Dim aryFileGroupDescriptor(512) As Byte ' = new byte[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
|
||||
Dim intCnt As Integer = 76
|
||||
Do While aryFileGroupDescriptor(intCnt) <> 0
|
||||
stbFileName.Append(Convert.ToChar(aryFileGroupDescriptor(intCnt), System.Globalization.CultureInfo.CreateSpecificCulture("de-DE")))
|
||||
intCnt += 1
|
||||
Loop
|
||||
oStream.Close()
|
||||
|
||||
Using oStream As IO.Stream = CType(e.Data.GetData("FileGroupDescriptor"), IO.Stream)
|
||||
Dim aryFileGroupDescriptor(512) As Byte ' = new byte[512]
|
||||
oStream.Read(aryFileGroupDescriptor, 0, 512)
|
||||
'// used to build the stbFileName from the aryFileGroupDescriptor block
|
||||
|
||||
'// this trick gets the stbFileName of the passed attached file
|
||||
Dim intCnt As Integer = 76
|
||||
Do While aryFileGroupDescriptor(intCnt) <> 0
|
||||
stbFileName.Append(Convert.ToChar(aryFileGroupDescriptor(intCnt), System.Globalization.CultureInfo.CreateSpecificCulture("de-DE")))
|
||||
intCnt += 1
|
||||
Loop
|
||||
oStream.Close()
|
||||
End Using
|
||||
|
||||
'Sonderzeichen entfernen
|
||||
Dim oTempFileName = DigitalData.Modules.Language.Utils.RemoveInvalidCharacters(stbFileName.ToString)
|
||||
Dim oTempFileName = DigitalData.Modules.Language.Utils.ConvertTextToSlug(stbFileName.ToString)
|
||||
LOGGER.Info("Slug for Filename: [{0}]", oTempFileName)
|
||||
|
||||
Dim oAttachments = e.Data.GetDataPresent("FileContents")
|
||||
Dim strOutFile As String = Path.Combine(Path.GetTempPath(), oTempFileName)
|
||||
'// create the full-path name
|
||||
@@ -64,35 +70,37 @@ 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 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(oMemoryStreamInput.Length, Int32)) As Byte
|
||||
'// set starting position at first byte and read in the raw data
|
||||
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)
|
||||
fsOutput.Close() ' // close the file
|
||||
Dim resultVersion = ClassFilehandle.Versionierung_Datei(strOutFile)
|
||||
If resultVersion <> "" Then
|
||||
strOutFile = resultVersion
|
||||
End If
|
||||
Dim finTemp As IO.FileInfo = New IO.FileInfo(strOutFile)
|
||||
'// always good to make sure we actually created the file
|
||||
If (finTemp.Exists = True) Then
|
||||
LOGGER.Info("Drop an Attachment - File: " & strOutFile)
|
||||
FilesDropped.Add("|OUTLOOK_ATTACHMENT|" & strOutFile)
|
||||
'Dim oMemoryStreamInput As IO.MemoryStream = CType(e.Data.GetData("FileContents", True), IO.MemoryStream) 'This returns nothing for an Email
|
||||
Using oStream As MemoryStream = CType(e.Data.GetData("FileContents", True), IO.MemoryStream)
|
||||
If oStream Is Nothing = False Then
|
||||
'// allocate enough bytes to hold the raw date
|
||||
Dim aryFileBytes(CType(oStream.Length, Int32)) As Byte
|
||||
'// set starting position at first byte and read in the raw data
|
||||
oStream.Position = 0
|
||||
oStream.Read(aryFileBytes, 0, CType(oStream.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)
|
||||
fsOutput.Close() ' // close the file
|
||||
Dim resultVersion = ClassFilehandle.Versionierung_Datei(strOutFile)
|
||||
If resultVersion <> "" Then
|
||||
strOutFile = resultVersion
|
||||
End If
|
||||
Dim finTemp As IO.FileInfo = New IO.FileInfo(strOutFile)
|
||||
'// always good to make sure we actually created the file
|
||||
If (finTemp.Exists = True) Then
|
||||
LOGGER.Info("Drop an Attachment - File: " & strOutFile)
|
||||
FilesDropped.Add("|OUTLOOK_ATTACHMENT|" & strOutFile)
|
||||
|
||||
'ReDim Preserve FilesDropped(0)
|
||||
'FilesDropped(0) = "|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")
|
||||
Return True
|
||||
Else
|
||||
LOGGER.Info("Attachment File from Outlook could not be created")
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End Using
|
||||
End If
|
||||
If e.Data.GetDataPresent("FileGroupDescriptor") Then
|
||||
Dim oApp As Outlook.Application
|
||||
@@ -115,9 +123,11 @@ Public Class ClassFileDrop
|
||||
End If
|
||||
|
||||
'Sonderzeichen entfernen
|
||||
subj = DigitalData.Modules.Language.Utils.RemoveInvalidCharacters(subj)
|
||||
Dim oSubjectSlug = DigitalData.Modules.Language.Utils.ConvertTextToSlug(subj)
|
||||
LOGGER.Info("Subject Slug for Filename: [{0}]", oSubjectSlug)
|
||||
|
||||
'hardcode a destination path for testing
|
||||
Dim oFilename As String = IO.Path.Combine(Path.GetTempPath, subj + ".msg")
|
||||
Dim oFilename As String = IO.Path.Combine(Path.GetTempPath, oSubjectSlug + ".msg")
|
||||
|
||||
oFilename = oFilename.Replace("?", "")
|
||||
oFilename = oFilename.Replace("!", "")
|
||||
@@ -146,6 +156,7 @@ Public Class ClassFileDrop
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
MsgBox("Error in Drop-File" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
||||
Return False
|
||||
End Try
|
||||
|
||||
Reference in New Issue
Block a user