从vb.net翻译了一个程序到C#,就是过不了,高手帮忙看看。
文章在这里:
HOW TO: Retrieve Unread Messages from Inbox by Using Outlook Object Model in Visual Basic .NET
http://support.microsoft.com/?kbid=313795
我翻译的在这里,就一行有错误,
error CS0029: 无法将类型“object”隐式转换为“Outlook.MailItem”
using System;
using System.Reflection;
namespace testOutlook1
{
class testOutlook1
{
static void Main(string[] args)
{
Outlook.Application oApp = new Outlook.ApplicationClass();
Outlook.NameSpace oNS= oApp.GetNamespace("MAPI");
oNS.Logon("Administrator", Missing.Value, false, true);
Outlook.MAPIFolder oInbox =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items oItems = oInbox.Items;
Console.WriteLine("Total : {0}\n", oItems.Count);
oItems = oItems.Restrict("[Unread] = true");
Console.WriteLine("Total Unread : {0}\n", oItems.Count);
int i;
Outlook.MailItem oMsg;
for (i = 1; i < oItems.Count; i++)
{
oMsg = oItems.Item(i); //出错在这行
Console.WriteLine(i);
Console.WriteLine(oMsg.SenderName);
Console.WriteLine(oMsg.Subject);
Console.WriteLine(oMsg.ReceivedTime);
Console.WriteLine(oMsg.Body);
Console.WriteLine("---------------------------");
}
oNS.Logoff();
oApp = null;
oNS = null;
oItems = null;
oMsg = null;
}
}
}