' System.Runtime.InteropServices.COMException'

时间:2014-05-02 11:24:12

标签: c# visual-studio-2012 outlook

我试图在c#.net应用程序中检索我的Outlook联系人。 但是在创建Outlook应用程序的对象时,我收到了错误

 "AnswerWizard = '((Microsoft.Office.Interop.Outlook.ApplicationClass.(outlookObj)).AnswerWizard' threw an exception of type 'System.Runtime.InteropServices.COMException'"

我尝试使用revsvr32" DLL Path"注册dll,但是我收到模块加载的错误但找不到DLLRegisterServer。

这是我写的代码:

        DataSet ds = new DataSet();
        ds.Tables.Add("Contacts");
        ds.Tables[0].Columns.Add("Email ID");
        ds.Tables[0].Columns.Add("FirstName");
        ds.Tables[0].Columns.Add("LastName");

        Microsoft.Office.Interop.Outlook.Items OutlookItems;
        Microsoft.Office.Interop.Outlook.Application outlookObj;
        MAPIFolder Folder_Contacts;

        outlookObj = new Microsoft.Office.Interop.Outlook.Application();
        Folder_Contacts =(MAPIFolder)outlookObj.Session.GetDefaultFolder  (OlDefaultFolders.olFolderContacts);
        OutlookItems = Folder_Contacts.Items;

        for (int i = 0; i < OutlookItems.Count; i++)
        {
            Microsoft.Office.Interop.Outlook.ContactItem contact =(Microsoft.Office.Interop.Outlook.ContactItem)OutlookItems[i + 1];
            DataRow dr = ds.Tables[0].NewRow();
            dr[0] = contact.Email1Address;
            dr[1] = contact.FirstName;
            dr[2] = contact.LastName;

            ds.Tables[0].Rows.Add(dr);
            if (i == 10)
                break;
        }
        dgvContacts.DataSource = ds.Tables[0];
        return ds;

我的计数为零。

1 个答案:

答案 0 :(得分:0)

我不认为Application.AnswerWizard曾在Outlook中工作过。你想做什么?

相关问题