我开发了一个内部网应用程序,其中下拉列表与outlook的全局地址列表数据绑定。代码如下所示:
Dictionary list = new Dictionary(); //创建Outlook应用程序。 Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
// Get the NameSpace information.
Microsoft.Office.Interop.Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
// oNS.Logon(oNS.CurrentProfileName, "*********", true, true);
// Get the default Contacts folder.
Microsoft.Office.Interop.Outlook.MAPIFolder oContacts = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts);
// Microsoft.Office.Interop.Outlook.AddressLists = oNS.AddressLists;
// Get the Items collection from the folder.
Microsoft.Office.Interop.Outlook.Items oItems = (Microsoft.Office.Interop.Outlook.Items)oContacts.Items;
Microsoft.Office.Interop.Outlook.ContactItem oCt = (Microsoft.Office.Interop.Outlook.ContactItem)oItems.GetFirst();
Microsoft.Office.Interop.Outlook.AddressLists addressbook=oNS.AddressLists;
Microsoft.Office.Interop.Outlook.AddressList addrList = oNS.GetGlobalAddressList();
foreach (Microsoft.Office.Interop.Outlook.AddressEntry addentry in addrList.AddressEntries)
{
Microsoft.Office.Interop.Outlook.ExchangeUser contact = addentry.GetExchangeUser();
if(contact!=null)
list.Add(contact.PrimarySmtpAddress, addentry.Name);
// string email = contact.Email1Address;
}
((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email")).DataSource = list;
((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email")).DataTextField = "Key";
((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email")).DataValueField = "Value";
((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email")).DataBind();
}
catch (System.Exception ex)
{
}
代码在开发系统中正常工作,但在服务器中出现错误,因为System.Runtime.InteropServices.COMException(0x80010001):检索具有CLSID {0006F03A-0000-0000-C000-000000000046}的组件的COM类工厂失败到期出现以下错误:80010001。
outllook已安装并配置为电子邮件帐户。
请帮助解决问题:
答案 0 :(得分:0)
您是否在运行Intranet应用程序的服务器上安装了Outlook?如果您这样做,请确保Outlook组件在该计算机上具有正确的权限。
答案 1 :(得分:-1)
一种有效的方法,
try { outlook = new Outlook.Application(); }
catch { outlook = new Outlook.Application(); }