I have two questions:
1: We have a public Outlook folder called Global Contacts that contains (you guessed it) a load of contacts available to everyone with an account on the server.
I can access it using this code:
Microsoft.Office.Interop.Outlo开发者_JAVA技巧ok._Application objOutlook; //declare Outlook application
objOutlook = new Microsoft.Office.Interop.Outlook.Application(); //create it
Microsoft.Office.Interop.Outlook._NameSpace objNS = objOutlook.Session; //create new session
Microsoft.Office.Interop.Outlook.MAPIFolder oAllPublicFolders; //what it says on the tin
Microsoft.Office.Interop.Outlook.MAPIFolder oPublicFolders; // as above
Microsoft.Office.Interop.Outlook.MAPIFolder objContacts; //as above
Microsoft.Office.Interop.Outlook.Items itmsFiltered; //the filtered items list
oPublicFolders = objNS.Folders["Public Folders"];
oAllPublicFolders = oPublicFolders.Folders["All Public Folders"];
objContacts = oAllPublicFolders.Folders["Global Contacts"];
itmsFiltered = objContacts.Items.Restrict(strFilter);//restrict the search to our filter terms
for (int i = 1; i <= itmsFiltered.Count; i++) //loop through filtered items
{
//do stuff
}
That's all fine and dandy. What I'd like to also do is a version of this to retrieve one specific contact basied on some sort of unique ID...how would I do this?
Is there some sort of unique ID field I can use to retrieve contacts? And a faster method than Restrict() (which can be pretty slow - we have thousands of contacts)?
2: Is there a way to get around Outlook 2003's "A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this?" dialog box that throws up every time I run this code? I know it's meant to be a security feature, so I'm guessing the answer to this may well be 'no', but thought I'd ask anyway.
Navigating through a public contact list from client side using brute force can never be fast. I'd suggest taking a look at Exchange Web Service (EWS) API to achieve the functionality you wanted via a web service from the server.
You can also bypass the annoying message from Outlook using EWS.
The other way to bypass the message is to use MAPI directly, and there are many examples. However, MAPI has the same problem I mentioned earlier: it can't be fast to get things done from client side using brute force.
Jez,
I know I was having the same problem with the "A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this?" error message, and I think your problem is the following line of code:
objOutlook = new Microsoft.Office.Interop.Outlook.Application(); //create it
Instead, try changing it to the following
objOutlook = Globals.ThisAddIn.Application(); //get current Outlook object
I think that should help you avoid that error message, or at least, that's what fixed it for me! :-)
Good luck! :-)
- If you know the entry id, you can just call
Namespace.GetItemFromID
. Otherwise search based on your custom unique id is the way to go. - You can use Extended MAPI (C++ or Delphi only) or Redemption (I am its author - any language)
精彩评论