Hi Peter,
The Object Modal of outlook catalogized the items as a few MAPI folders,
e.g. Contacts, Send Mail and so on.
So if we wants to iterate all the item in the outlook we may need to get
the folder first.
e.g.
Outlook.MAPIFolder mf =
olApp.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolde
rContacts);
The code line above will retrieve the Contact folder and then we can
iterate the items in the folder.
The code I post will runs fine on my side.
Have you tried the exact code I post in my last post?
Which code line gives out the error message?
To isolate the problem, you may try to add a reference to the outlook and
then copy and paste the code below into an console application for a test.
using System;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace AutoOutLook
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Outlook.Application olApp = new Outlook.ApplicationClass();
Outlook.MAPIFolder mailFolder =
olApp.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolde
rInbox);
Outlook.MailItem mItem = (Outlook.MailItem)mailFolder.Items[1];
Console.WriteLine(mItem.Subject);
foreach( object mi in mailFolder.Items)
{
if ( mi as Outlook.MailItem !=null)
Console.WriteLine(((Outlook.MailItem)mi).Subject);
}
}
}
}
You may have a try and let me know the result.
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.