add preview of eml & msg files
This commit is contained in:
@@ -24,6 +24,9 @@ Public Class DocumentViewer
|
||||
Private _logConfig As LogConfig
|
||||
Private _logger As Logger
|
||||
|
||||
' List of all created temp files when converting msg files
|
||||
Private _TempFiles As New List(Of String)
|
||||
|
||||
Private Sub DocumentViewer_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||
Dim zoomModes As New Dictionary(Of ZoomMode, String) From {
|
||||
{ZoomMode.Zoom50, "50%"},
|
||||
@@ -40,6 +43,8 @@ Public Class DocumentViewer
|
||||
cbZoom.Items.Add(item.Value)
|
||||
Next
|
||||
|
||||
_TempFiles.Clear()
|
||||
|
||||
UpdateMainUi()
|
||||
End Sub
|
||||
|
||||
@@ -59,23 +64,62 @@ Public Class DocumentViewer
|
||||
|
||||
CloseDocument()
|
||||
|
||||
_docPath = filepath
|
||||
statusLabel.Text = _docPath
|
||||
|
||||
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
|
||||
GdViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter
|
||||
GdViewer.DisplayFromFile(filepath)
|
||||
GdViewer.Focus()
|
||||
|
||||
DoLoadFile(filepath)
|
||||
|
||||
statusLabel.Text = _docPath
|
||||
|
||||
UpdateMainUi()
|
||||
End Sub
|
||||
|
||||
Public Sub DoLoadFile(FilePath As String)
|
||||
Try
|
||||
Dim oFileInfo = New IO.FileInfo(FilePath)
|
||||
Dim oExtension As String = oFileInfo.Extension
|
||||
|
||||
Select Case oExtension
|
||||
Case ".msg"
|
||||
Dim oMsg As New Independentsoft.Msg.Message(FilePath)
|
||||
' TODO: Improve Encoding, maybe convert based on encoding
|
||||
oMsg.Encoding = System.Text.Encoding.UTF32
|
||||
Dim oMime = oMsg.ConvertToMimeMessage()
|
||||
Dim oTempFileName = IO.Path.GetTempFileName()
|
||||
oMime.Save(oTempFileName, True)
|
||||
|
||||
RichEditControl1.LoadDocument(oTempFileName, DevExpress.XtraRichEdit.DocumentFormat.Mht)
|
||||
|
||||
_TempFiles.Add(oTempFileName)
|
||||
|
||||
RichEditControl1.Visible = True
|
||||
RichEditControl1.Dock = DockStyle.Fill
|
||||
Case ".eml"
|
||||
RichEditControl1.LoadDocument(FilePath, DevExpress.XtraRichEdit.DocumentFormat.Mht)
|
||||
|
||||
RichEditControl1.Visible = True
|
||||
RichEditControl1.Dock = DockStyle.Fill
|
||||
Case Else
|
||||
_docPath = FilePath
|
||||
|
||||
GdViewer.DisplayFromFile(_docPath)
|
||||
GdViewer.Focus()
|
||||
|
||||
RichEditControl1.Visible = False
|
||||
RichEditControl1.Dock = DockStyle.None
|
||||
End Select
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub CloseDocument()
|
||||
GdViewer.CloseDocument()
|
||||
UpdateMainUi()
|
||||
End Sub
|
||||
|
||||
Private Sub btnOpen_Click(sender As Object, e As EventArgs) Handles btnOpen.Click
|
||||
Private Sub btnOpen_Click(sender As Object, e As EventArgs)
|
||||
CloseDocument()
|
||||
|
||||
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
|
||||
@@ -452,4 +496,13 @@ Public Class DocumentViewer
|
||||
MagnifierToolStripMenuItem.Checked = True
|
||||
GdViewer.Focus()
|
||||
End Sub
|
||||
|
||||
Private Sub DocumentViewer_Disposed(sender As Object, e As EventArgs) Handles Me.Disposed
|
||||
For Each oFile In _TempFiles
|
||||
Try
|
||||
IO.File.Delete(oFile)
|
||||
Catch ex As Exception
|
||||
End Try
|
||||
Next
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user