我有asp.net网站,其中listview填充了products.i添加按钮到listview项目,用于打开包含产品信息的outlook新电子邮件。问题是当新的电子邮件Outlook窗口打开时,我无法在我的网站中导航,直到我关闭Outlook窗口(它接口像浏览器是忙)。当Outlook窗口仍处于打开状态时,有没有办法在网站上导航?
ASP:
<asp:LinkButton ID="promote_link" runat="server" Text="send with mail" CommandName="mail"/>
C#:
protected void site_search_results_list_ItemCommand(object sender, ListViewCommandEventArgs e)
{
Label lblProductId = (Label)e.Item.FindControl("lblProductId");
if (e.CommandName == "mail")
{
Outlook.Application outlookApp = new Outlook.Application();
Outlook._MailItem mailItem = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = "subject";
mailItem.Display(true);
outlookApp.Quit();
}
}
答案 0 :(得分:2)
Microsoft目前不建议也不支持从任何无人参与的非交互式客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT服务)自动化Microsoft Office应用程序,因为Office在此环境中运行Office时,可能会出现不稳定的行为和/或死锁。
如果要构建在服务器端上下文中运行的解决方案,则应尝试使用已为安全无人值守执行的组件。或者,您应该尝试找到允许至少部分代码在客户端运行的替代方法。如果从服务器端解决方案使用Office应用程序,则应用程序将缺少许多成功运行的必要功能。此外,您将承担整体解决方案稳定性的风险。您可以在Considerations for server-side Automation of Office文章中详细了解相关内容。
如果您使用Exchange托管邮箱,请考虑使用EWS(Exchange Web服务)。有关详细信息,请参阅EWS Managed API, EWS, and web services in Exchange。