I'm trying an ASP.NET App and I have a problem with OutLook.
Code behind :
public Outlook()
{
// Check whether there is an Outlook process running.
if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
{
// If so, use the GetActiveObject method to obtain the process and cast it to an Application object.
OutlookApplication = Marshal.GetActiveObject("Outlook.Application") as Application;
}
else
{
// If not, create a new instance of Outlook and log on to the default profile.
OutlookApplication = new Application();
NameSpace nameSpace = OutlookApplication.GetNamespace("MAPI");
nameSpace.Logon("", "", missing, missing);
nameSpace = null;
}
}
}
When I play the app then :
System.Runtime.InteropServices.COMException (0x800401E3): Opération non >disponible (Exception de HRESULT : 0x800401E3 (MK_E_UNAVAILABLE))
I already read this :
I would guess that you are running Visual Studio as Administrator (started via Run as Administrator) while Outlook was opened as user, who was logged in as under Windows logon. So the Visual Studio is running under different user than Outlook client.
But I dont know how to fix it.
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.
You may consider using EWS in case of Exchange profiles, see EWS Managed API, EWS, and web services in Exchange for more information. Or use a low-level API on which Outlook is based on. As well as any third-party wrappers around that API - for example, Redemption.
User contributions licensed under CC BY-SA 3.0