我正在尝试使用C#(Visual Studio 2010)连接到Outlook 2010中的公用文件夹。 我从Microsoft Website:
复制了以下代码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”被修改了,我不知道我忘记了什么或做错了什么。 这是一个带有错误消息的screenshot。
答案 0 :(得分:0)
您需要使用界面
Microsoft.Office.Interop.Outlook.Application outlook = new Microsoft.Office.Interop.Outlook.Application()
或禁用此程序集的Interop类型的嵌入(参考 - &gt; Microsoft.Office.Interop.Outlook(右键单击) - &gt;属性 - &gt;设置&#39;嵌入互操作类型&#39;为假)< / p>
答案 1 :(得分:0)
更改行
Outlook._Application olApp = new Outlook.ApplicationClass();
到
Outlook._Application olApp = new Outlook._Application();