Friday, May 12, 2006

Sample VB.Net code to open outlook msg file using the Priasoft MSG Library for .Net

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim MsgFile As msgparser.net.MsgFile

' Open a MSG file

Try

MsgFile = New _
msgparser.net.MsgFile("C:\Outlook MSG files\A Special Invitation from the Pat Tillman Foundation and Roy's.msg")

Catch ex As Exception

'TODO: Handle any exceptions here

End Try

' Get the subject of the message
Debug.WriteLine(MsgFile.Subject)

' Get the number of attachments
Debug.WriteLine(MsgFile.Attachments.Count)

' Save all attachments, if any
If MsgFile.Attachments.Count <> 0 Then

For I As Integer = 0 To MsgFile.Attachments.Count
MsgFile.Attachments(I).SaveAttachment("c:\attachments", MsgFile.Attachments(I).ShortName)

Next

End If

' Get the senders address
Debug.WriteLine(MsgFile.Sender.RecipientAddress)

' Get the message type
Debug.WriteLine(MsgFile.IPM_Class)

' Save the MSG file to a png image
Dim X As New msgparser.net.msgExport(MsgFile)

X.SaveMessageAs("C:\MSGConvertedToPNG.png", "", msgparser.net.msgExport.SaveTypes.PNG)

MsgFile.Close()

End Sub

No comments: