Information générale
Titre:
Cannot get Outlook mailitems
I trying to read my e-mail messages via Outlook but I cannot get it to work. I using VS2003 and PIAs (not VSOT). Any help??
Here is the code:
ol = new Outlook.Application();
ns = ol.GetNamespace("MAPI");
outbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
But if I try to get the mailitems via:
foreach (Outlook.MailItem it in inbox.Items)
{
MessageBox.Show(it.Subject);
}
or
Outlook.Items items = inbox.Items;
for (int i = 1; i < items.Count; i++)
{
Outlook.MailItem item = (Outlook.MailItem)items[i];
}
I get a unhandled exception of type 'System.InvalidCastException'
What am I doing wrong?
John
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement