I am working on an outlook application and came to know that Folder object is the new one which has superseeded MAPI.Folder which was being used in earlier versions. Now the question is: 1. i want to read .pst file by using the Folder object so that it is able to retrieve all the folders that contain incoming mails (inbox folders) and outgoing mails respectively. 2. For this i need to differentiate between the folder types for which i am unable to find out any method/property? 3. Currently i have to pass the MAPI Folder as the root folder through it is traversing successfully but it also picks up Calendar object and Deleted Folder as well which i don't want (as i told that i want to get mails from all the inbox type folders and sent mails).
Thanks in advance.
Outlook.MAPIFolder inboxFolder = outlookNs.Stores[pstName].GetRootFolder(); //
getIncomingMails(inboxFolder);
private void getIncomingMails(Outlook.MAPIFolder rootFolder)
{
List<Outlook.MailItem> mailItems = new List<Outlook.MailItem>();
Outlook.Folders subFolders = rootFolder.Folders;
foreach (Outlook.Folder folder in subFolders)
{
Debug.WriteLine(folder.GetType().ToString());
var restrictedItems = folder.Items.Restrict(filter);
restrictedItems.Sort("[ReceivedTime]", true); //descending
foreach (var item in restrictedItems)
{
if (item is Outlook.MailItem)
{
mailItems.Add(item as Outlook.MailItem);
}
}
}