How to integrate .OST file with C#?

Updated on January 8, 2019 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on November 16, 2018

I want to integrate .OST file with C#. I created a method where pass “File Path” & “File Name”. I want to read them with the C# application. I have generated this code:

private static IEnumerable<mailitem> readPst(string pstFilePath, string pstName)
{
List<mailitem> mailItems = new List<mailitem>();
try
{
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
NameSpace outlookNs = app.GetNamespace("MAPI");
// Add PST file (Outlook Data File) to Default Profile
outlookNs.AddStore(pstFilePath);
MAPIFolder rootFolder = outlookNs.Stores[pstName].GetRootFolder();
Folders subFolders = rootFolder.Folders;
foreach (Folder folder in subFolders)
{
if (folder.Name == "Inbox")
{
Items items = folder.Items;
foreach (object item in items)
{
if (item is MailItem)
{
MailItem mailItem = item as MailItem;
mailItems.Add(mailItem);
}
}
}
}
progressMaxVal =(int) mailItems.Count;
}
catch (System.Exception ex)
{
}
return mailItems;
}</mailitem></mailitem></mailitem>

After passing this code exception occur

“The Outlook data file (.pst) failed to load for this session.”

I have tried many methods to resolve this exception but all methods get failed. After wasting so much time on this error, finally I have submitted this exception on Codeguru forum but didn’t get any solution yet. After so many searches, I have found some useful forums where users also faced the same issue. I have reviewed these forums but can’t understand which one will fix this exception. Please suggest.

https://codepad.co/snippet/dyjIh4PQ

http://www.csharpforums.net/showthread.php/4254-Facing-Errors-while-opening-ost-file-in-C

https://www.stellarinfo.com/convert-ost-to-pst.php

http://p2p.wrox.com/c-2012-5-0-general-discussion/100067-facing-issue-while-opening-ost-file-c.html

  • Liked by
Reply