How to retrieve the Outlook folder of a mail item (Outlook.MailItem)?

筅森魡賤 提交于 2019-12-12 13:28:18

问题


I am getting my default inbox folder via inboxFolder = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox

Elsewhere in my code, I begin doing a foreach loop to extract specific information I want from these MailItems

foreach (var item in this.inboxFolder.Items)
{
   Outlook.MailItem mailItem = (Outlook.MailItem)item;
   //.... doing stuff here
   string SenderEmail = mailItem.SenderEmailAddress;
   string SenderName = mailItem.SenderName;
   string FolderLocation = mailItem.???;  //how to retrieve folder location?
   //.... more stuff here
}

For example: A user may have created a subfolder called 'Test' shown below.


回答1:


Do you mean folder path? Use MAPIFolder.FullFolderPath. Or MAPIFoldert.Name if you only need the name.

Also keep in mind that the value will be the same for all items in the folder, so there is no reason to evaluate it on each step of the loop.




回答2:


Thank you for the pointer guys. However I was having some trouble implementing the same initially. Here is how I solved it, just in case if some one faces the same issue.

Outlook.MAPIFolder parentFolder = mailItemToDelete.Parent as Outlook.MAPIFolder;
string FolderLocation = parentFolder.FolderPath;

The Parent object is dynamic and hence was causing issue.



来源:https://stackoverflow.com/questions/16011029/how-to-retrieve-the-outlook-folder-of-a-mail-item-outlook-mailitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!