Create Outlook meeting on SharePoint page - sharepoint

Is it posible to create outlook meeting on Sharepoint page behalf on current sharepoint user?
I try to create meeting by button click with next code
Application oApp = new Microsoft.Office.Interop.Outlook.Application();
AppointmentItem appointment = (AppointmentItem)oApp.CreateItem(OlItemType.olAppointmentItem);
appointment.Start = DateTime.Now.AddHours(1);
appointment.End = DateTime.Now.AddHours(2);
appointment.Subject = "Some subject";
appointment.Body = "Some body";
appointment.Recipients.Add("user1#somemail.com");
appointment.Recipients.Add("user2#somemail.com");
appointment.Save();
But i get this error, on calling appointment.Recipients
Operation aborted (Exception HRESULT: 0x80004004 (E_ABORT))
When i run this code in console application it works fine. Any ideas?
Thanks in advance

The Considerations for server-side Automation of Office article states the following:
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.
If you deal with Exchange profiles, you may consider using EWS (Exchange Web Services). See EWS Managed API, EWS, and web services in Exchange for more information.

Related

When closing an Excel file on a terminal server it saves to a different location than it was in

In our organisation a problem occurs when saving Excel files.
Whenever we close a file there is a 50/50 chance that it saves in the location it was already in, but the other times it saves where another file was last saved.
We are all working on a Terminal Server (Windows 2019) using Office 2019.
Did anyone else stumble upon this as well? And perhaps found a solution?
The Considerations for server-side Automation of Office article states the following:
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.
I'd suggest using the Open XML SDK instead if you deal with open XML documents only, see Welcome to the Open XML SDK 2.5 for Office for more information.

Excel OLE automation in a Windows service

I have a Windows service filling cells in an Excel Workbook via OLE Automation.
The save process is not working, the file is never saved. But when done in a GUI app, the save process works.
The service user is an administrator account. I suspect the interaction with the Desktop.
Any idea?
Don't do this. Find another solution. Microsoft does not support or recommend OLE automation of Office software from anywhere but a workstation desktop session. I can't paraphrase any better than what they say directly, so here's the advice (link above goes into more detail) :
All current versions of Microsoft Office were designed, tested, and configured to run as end-user products on a client workstation. They assume an interactive desktop and user profile. They do not provide the level of reentrancy or security that is necessary to meet the needs of server-side components that are designed to run unattended.
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.
If you need your service to store data, a database is probably a good choice. Any users that require the data in an excel spreadsheet could populate their documents from the database. You could even set up template documents to do this automatically.
I had the same problem, run a Delphi software as service, with an administrator user and it gave to me a lot of errors in the read/write process like SaveAs method of Workbook class failed
The solution for read/save was create both folders below:
C:\Windows\System32\config\systemprofile
C:\Windows\SysWOW64\config\systemprofile\
There isn't much sense at all, but it worked.

How to send email through VBA when scheduled in Windows Task Scheduler?

I have code which will send email when done through a button click.
I have scheduled the same code to run periodically through Task Scheduler. The mail gets in draft stage.
Issue 1: if I use .Send, there is a security pop up with allow or deny options
Issue 2: to avoid the above pop up, I used .Display, wait for the application and sendkeys --> this is working when run through button click but when run through scheduler the email stays in draft stage.
Issue 1 : if I use .send in mail, it ask for a security pop up with allow or deny option
This is a standard security prompt in Outlook. "Security" in this context refers to the so-called "object model guard" that triggers security prompts and blocks access to certain features in an effort to prevent malicious programs from harvesting email addresses from Outlook data and using Outlook to propagate viruses and spam. These prompts cannot simply be turned off, except in Outlook 2007 with an anti-virus application running. This page discusses strategies for avoiding security prompts.
Issue 2 : to avoid the above pop up, I have used .display, wait for the application and sendkeys -->
All current versions of Microsoft Office were designed, tested, and configured to run as end-user products on a client workstation. They assume an interactive desktop and user profile. They do not provide the level of reentrancy or security that is necessary to meet the needs of server-side components that are designed to run unattended.
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.
As a possible workaround, you may use a low-level API which doesn't trigger security prompts - Extended MAPI. Or just any wrappers around this API such as Redemption. It allows bridging both issues.

Access Denied OutLook DCOM

I'm trying an ASP.NET App and I have a problem with OutLook.
Code behind :
OutlookApplication = new Application();
NameSpace nameSpace = OutlookApplication.GetNamespace("MAPI");
nameSpace.Logon("", "", missing, missing);
nameSpace = null;
When I play the app with Visual Studio it's ok.
When I play the app with IIS then :
System.UnauthorizedAccessException: Retrieving the COM class factory for >component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the >following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 >(E_ACCESSDENIED)).
I already tried to change DCOM Configuration for "OutLook Message Attachment" with :
Proprieties -> Identity -> Execute user
Proprieties -> Security -> all kind of acces autorized for "everybody".
NB : I have no problem with others Office programm (Excel and Word).
I'm trying an ASP.NET App and I have a problem with OutLook.
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.
As a workaround you may consider using a low-level API on which Outlook is based on (Extended MAPI) or any third-party wrappers around that API, for example, Redemption.

Pass data to Word 2013 Template

I am wondering if it is possible to pass data from an ASP.NET MVC controller to Microsoft Word 2013 Template, using an instantiated Host Item, and bind it to content controls within the template.
Ideally I would like to pass the data to the ThisDocument class and have the data applied to the template's databindings, however I cannot find how to instantiate and use the ThisDocument object after I have created an interop instance of the Word template.
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. You can read more about that in the Considerations for server-side Automation of Office article.
Consider using the Open XML SDK, see Welcome to the Open XML SDK 2.5 for Office for more information. Or any other third-party components designed for the server-side execution.

Resources