从vb.net翻译了一个程序到C#,就是过不了,高手帮忙看看。

DemoImage 2003-07-17 08:55:15
文章在这里:
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;
}

}
}
...全文
77 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiujinwen 2003-07-17
  • 打赏
  • 举报
回复
发贴的兄弟。千万不要用.Net来进行CDO1.2x和Mapi接口的编程。你看看下面的文档就知道了,我们就是开发完以后发现系统不稳定,然后查资料才知道.Net不支持CDO1.2x和Mapi
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ExchReadme/htms/DevelopmentToolsReadMeJune2003.asp

具体说明如下啊。。。。


Support Policy for Exchange Development Technologies in .NET Framework Applications
The Microsoft Knowledge Base article 813349 provides information about which Exchange development APIs are supported in applications using Microsoft Visual Studio .NET and the Microsoft .NET Framework. See the Knowledge Base article for additional details, as this support policy may change.

The following scenarios are currently supported in a .NET environment.

API Managed Code Support Policy
System.Web.Mail Supported
WebDAV Supported
WMI Supported
CDOSYS Supported, but System.Web.Mail is suggested
CDOEXM Supported using COM interopability
ExOLEDB Supported using COM interoperability
CDOEX Supported using COM interopability
CDO 1.2x Not supported
CDONTS Not supported. Use System.Web.Mail
MAPI Not Supported

Microsoft is committed to improving the .NET Framework environment. The supportability status of some of these components may change without notice.
thp 2003-07-17
  • 打赏
  • 举报
回复
无所求,站一会就走
li_aiwu 2003-07-17
  • 打赏
  • 举报
回复
?
是三位!
:>
li_aiwu 2003-07-17
  • 打赏
  • 举报
回复
呵呵!
两位高手跟我抢分啊?
哈!!
xhan2000 2003-07-17
  • 打赏
  • 举报
回复
oMsg = (Outlook.MailItem)oItems.Item(i);
TheAres 2003-07-17
  • 打赏
  • 举报
回复
改成这样试试:

oMsg = (Outlook.MailItem)oItems.Item(i);
saucer 2003-07-17
  • 打赏
  • 举报
回复
oMsg = (Outlook.MailItem)oItems.Item(i);
li_aiwu 2003-07-17
  • 打赏
  • 举报
回复
无法隐式转换你就显式转换!
试试:
oMsg = (Outlook.MailItem)oItems.Item(i);
或者:
oMsg = (Outlook.MailItem)oItems.Item[i];

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧