正在连接Outlook 2010公用文件夹
本文关键字:文件夹 2010 Outlook 连接 | 更新日期: 2023-09-27 18:29:28
我正在尝试使用C#(Visual Studio 2010)连接到Outlook 2010中的公用文件夹。我从微软网站复制了以下代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// TODO: Add code here to start the application.
Outlook._Application olApp = new Outlook.ApplicationClass();
Outlook._NameSpace olNS = olApp.GetNamespace("MAPI"); Outlook._Folders oFolders;
oFolders = olNS.Folders;
Outlook.MAPIFolder oPublicFolder = oFolders["Public Folders"];
oFolders = oPublicFolder.Folders;
Outlook.MAPIFolder oAllPFolder = oFolders["All Public Folders"];
oFolders = oAllPFolder.Folders;
Outlook.MAPIFolder oMyFolder = oFolders["My Public Folder"];
Console.Write(oMyFolder.Name);
}
}
}
我的问题是"ApplicationClass"被划了红线,我不知道我忘记了什么或做错了什么。这是一张带有错误消息的屏幕截图。
您需要使用接口
Microsoft.Office.Interop.Outlook.Application outlook = new Microsoft.Office.Interop.Outlook.Application()
或禁用嵌入此程序集的互操作类型(引用->Microsoft.Office.Interop.Outlook(右键单击)->属性->将"嵌入互操作类型"设置为False)
更改行
Outlook._Application olApp = new Outlook.ApplicationClass();
至
Outlook._Application olApp = new Outlook._Application();