C# Outlook add-in get selected emails

久未见 提交于 2019-12-22 07:06:09

问题


I want to get all selected emails in my Outlook 2010 add-in. I found this MSDN tutorial, but I am a beginner at C#, and I don't quite understand this line of code: Object selObject = this.Application.ActiveExplorer().Selection[3];

I believe Selection[] is something like overridden operator, indexer in C#. But, is there any way to see implementation of it? If I go through the code, I only see interfaces but not implementations. So I don't know the structure of the Selection object. What is really behind the operator [].

Also, why do the selected items begin at index 1 and not 0?


回答1:


That lines retrieves the third selected message.
Selection[] is equivalent to Selection.Item() - Item function is marked as the indexed property accessor.
You cannot see the implementation - it is all in the Outlook Object Model.
All Outlook collections begin with 1, not 0. This is how it used to be in VB, so the Outlook Object Model uses the same convention.




回答2:


I know it's a little late but this question ranks highly in search engines. Here is the solution I use to get selected emails in Outlook Interop:

internal static IEnumerable<MailItem> GetSelectedEmails()
        {
            foreach (MailItem email in new Microsoft.Office.Interop.Outlook.Application().ActiveExplorer().Selection)
            {
                yield return email;
            }
        }


来源:https://stackoverflow.com/questions/14813402/c-sharp-outlook-add-in-get-selected-emails

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