在Outlook.Items集合中需要Outlook.Items.Find()结果的索引

时间:2011-03-28 19:21:24

标签: c# outlook indexing find contacts

Items.Find()返回的对象中是否有任何内容指示所述对象在调用Find()的集合中的位置?

Outlook.Application App = new Outlook.Application();
Outlook.MAPIFolder contactFolder = App.Session.GetDefaultFolder(
    Outlook.OlDefaultFolders.olFolderContacts);
Outlook.Items contactItems = contactFolder.Items;

Outlook.ContactItem matchItem = contactItems.Find(
    "@SQL=urn:schemas:contacts:cn LIKE '" + searchString + "%'");

此时我需要matchItem集合中的contactItems索引。这可能吗?

1 个答案:

答案 0 :(得分:0)

matchItem指向的引用应该等于Items集合中的引用。因此,您应该能够遍历Items集合并通过引用相等性查找索引。您需要强类型列表中的项目:

//Change how you're accessing the items of this folder
//the new list should have the same references as the Items property
var contactItems = contactFolder.Items.OfType<Outlook.ContactItem>().ToList();
...
//then use the List's built-in IndexOf() function:
var index = contactFolder.IndexOf(matchItem);