TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
RS Prajapati
NA
52
13.4k
How to read .OST file with c#.Net
Oct 13 2014 5:31 AM
PST/OST file integration with C# Issue
Posted on: 08 Oct 2014
I am using Microsoft.Office.Interop.Outlook Version 12.0.0.0 to read my outlook pst file but when compiler reaches this code outlookNs.AddStore(pstFilePath); it gives exception that “The Outlook data file (.pst) failed to load for this session.” i have triedoutlookNs.AddStoreEx(pstFilePath); also but the error was same ….any sugession ??
NOT ABLE TO READ PST/OST FILE THROUGH C#
Here I pass PST File Path & Name
IEnumerable
mailItems = readPst(strSource[0].ToString(), strSource[1].ToString());
Here is the Method
private static IEnumerable
readPst(string pstFilePath, string pstName)
{
List
mailItems = new List
();
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();
// Traverse through all folders in the PST file
// TODO: This is not recursive, refactor
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);
}
}
}
}
// Remove PST file from Default Profile
//outlookNs.RemoveStore(rootFolder);
progressMaxVal =(int) mailItems.Count;
}
catch (System.Exception ex)
{
}
return mailItems;
}
Reply
Answers (
15
)
Transfer data between TreeViews
display the data of gridview row