Friday, 18 August 2017 07:27

Add Message to PST File in C#, VB.NET

Written by  support iceblue
Rate this item
(0 votes)

In the previous article, we have introduced how to read a PST file and get the folder information from it. This article will show you how we can add existing mail message files into PSF file for archiving.

Step 1: Load a PST file from disk into an instance of OutlookFile class.

OutlookFile outlookFile = new OutlookFile(@"C:\Users\Administrator\Documents\Outlook Files\Sample.pst");

Step 2: Load a MSG file into an instance of OutlookItme class.

OutlookItem item = new OutlookItem();
item.LoadFromFile(@"C:\Users\Administrator\Documents\Outlook Files\Sample.msg");

Step 3: Get inbox folder from PST file.

OutlookFolder inboxFolder = outlookFile.RootOutlookFolder.GetSubFolder("Inbox");

Step 4: Add the MSG file to inbox folder.

inboxFolder.AddItem(item);

Full Code:

[C#]
OutlookFile outlookFile = new OutlookFile(@"C:\Users\Administrator\Documents\Outlook Files\Sample.pst");
OutlookItem item = new OutlookItem();
item.LoadFromFile(@"C:\Users\Administrator\Documents\Outlook Files\Sample.msg");
OutlookFolder inboxFolder = outlookFile.RootOutlookFolder.GetSubFolder("Inbox");
inboxFolder.AddItem(item);
Console.WriteLine("Completed");
[VB.NET]
Dim outlookFile As New OutlookFile("C:\Users\Administrator\Documents\Outlook Files\Sample.pst")
Dim item As New OutlookItem()
item.LoadFromFile("C:\Users\Administrator\Documents\Outlook Files\Sample.msg")
Dim inboxFolder As OutlookFolder = outlookFile.RootOutlookFolder.GetSubFolder("Inbox")
inboxFolder.AddItem(item)
Console.WriteLine("Completed")

Additional Info

  • tutorial_title:
Last modified on Friday, 18 August 2017 07:34