0

I'm trying to connect to a Public Folder in Outlook 2010 with C# (Visual Studio 2010). I copied following code from a 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);
        }
    }
}

My problem is that "ApplicationClass" is redlined and I don't know what I've forgotten or done wrong. Here's a screenshot with the error message.

John Saunders
  • 160,644
  • 26
  • 247
  • 397

2 Answers2

0

You need to use interface

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

or disable embedding of Interop types for this assembly (References -> Microsoft.Office.Interop.Outlook (right click) -> Properties -> Set 'Embed Interop Types' to False)

RenDishen
  • 928
  • 1
  • 10
  • 30
0

Change the line

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

to

Outlook._Application olApp = new Outlook._Application();
Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78