0

我正在尝试使用 C# (Visual Studio 2010) 连接到 Outlook 2010 中的公用文件夹。我从Microsoft 网站复制了以下代码:

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”是红线的,我不知道我忘记了什么或做错了什么。这是带有错误消息的屏幕截图。

4

2 回答 2

0

您需要使用界面

Microsoft.Office.Interop.Outlook.Application outlook = new Microsoft.Office.Interop.Outlook.Application()

或禁用此程序集的互操作类型的嵌入(参考 -> Microsoft.Office.Interop.Outlook(右键单击)-> 属性 -> 将“嵌入互操作类型”设置为 False)

于 2014-11-06T14:18:48.443 回答
0

换行

Outlook._Application olApp = new Outlook.ApplicationClass();

Outlook._Application olApp = new Outlook._Application();
于 2014-11-06T14:54:51.453 回答