I am using Microsoft.Office.Interop to open publisher from c# code. The issue is that unlike other office apps it does not provide the option to stop display alerts. Is there a way around this or a reason?
This is the way it is used for Word / Excel:
Microsoft.Office.Interop.[OFFICE_APP].Application app = new Microsoft.Office.Interop.[OFFICE_APP].Application();
app.DisplayAlerts = false;
You are correct that there is no option to disable alerts. What alert exactly is it that you need to supress?
For instance, if your Publisher file contains macros, you can avoid the warning regarding macros by setting Application.AutomationSecurity (https://msdn.microsoft.com/EN-US/library/office/ff939580.aspx) to msoAutomationSecurityForceDisable (https://msdn.microsoft.com/en-us/library/microsoft.office.core.msoautomationsecurity.aspx). This is the only alert I've ever needed to supress personally, but I'd be interested to know if you've run into another one.
I'm not sure whether there is a reason, but there are many discrepancies between the different object models in Microsoft Office, so perhaps you simply shouldn't expect it to work the same. For example, Excel doesn't have any Tags collection, whereas Publisher and Word do, but they're implemented quite differently.
Related
I frequently receive ok-only prompts while automating add-ins in Excel, stating that Microsoft Excel is waiting for another application to complete an OLE action Error. How to use Interop.dll to show a custom message and handle this error programmatically. Before receiving the promptenter link description here
While You possibly can catch these exceptions depending on your automation framework and do something with it - these type of errors typically comes from not closing the files properly when changing from one to another.
Make sure you dispose all that can be disposed and close all which can be closed in reverse order obviously and it should go away.
If You need more details do post your code for opening and closing looks like a bug there which will make it not coming up.
You do not technically have to use interop, could you consider using a more modern package for interacting with excel?
If you are using google drive / file stream then this may be the problem. Turn off "Real Time Presence in Microsoft Office" then the messages go away.
I am using Word (from 2007 to 2013) to convert documents to PDFA format,
and i'm having trouble with users who have certain add-ins. When they use the system they get an assortment of COM Exceptions like RPC_E_SERVERCALL_RETRYLATER and (0x800706BA) RPC server unavailable.
If they disable the add-ins it works fine. Problem is that the add-ins are required so that simple solution is out the window. (Also I know that using word for this kind of thing is frowned upon, and we are looking into getting something better, but until the business side want's to pay, we are stuck with this)
The new plan is to start word with the /a parameter to make it start without add-ins.
I have seen another question How can I start MS Office Word from .NET without Add-ins?
Where there is a working solution for one instance of Word,
//startup without plugins
System.Diagnostics.Process.Start(
#"Winword.exe",
#"/a");
//give a time for startup
Thread.Sleep(2000);
//attach to office
Application officeApplication = (Application)Marshal.GetActiveObject("Word.Application");
My question is two fold: Is it possible to set startup parameters when you start word like this
var _word = new Word.Application();
So I don't have to use Process.start();
And if not, how do I do a late bind to a specific word instance (GetActiveObject(), always gets the oldest word instance), perhaps there is some other method?
To your first question, there's no way to pass parameters or otherwise influence how Word starts when using the new keyword. The instructions for starting the application are in the Registry, so it would involve changing how the new keyword is implemented in the Registry. And since this Registry entry also determines how Windows Explorer starts the Word.Application, changing the Registry entry would also change the way Word works for the user.
It is possible to unload add-ins after an instance of Word has started via the Application.COMAddins property. This is the equivalent of unchecking the boxes next to the Add-in entries in the COM Add-ins dialog box in the Word UI. I would test whether doing this in the UI allows your software to work properly.
If it does, you can incorporate this in your code - no need to worry about starting Word without the add-ins.
Which brings us to the second question: GetActiveObject is only able to access the single instance of Word (any Office application) registered in the ROT. By design, Office applications register only a single instance in the ROT and usually, this will be the first instance. There are a couple of KB articles on MSDN that describe this. The only work-around is to start two instances of Word in the user profile, "hiding" the first (the registered) one and presenting the second to the user.
But this can be tricky, so if it works, I'd go with the suggestion about the COMAddins collection to unload the problem Add-ins.
(I'm currently on a mobile device. Next time I'm on my main machine I'll try to remember to paste in the links to the KB articles on the ROT.)
I'm trying to create an excel file from ASP.NET. I assume this file is created somewhere temporary right? How can I get this location?
What are you using to create the Excel file? Since you have an ASP.NET tag I hope you are not trying to do this with Office COM Automation, it is not supported and trust me it is very very unreliable. See this link from Microsoft http://support.microsoft.com/kb/257757
Key message from the link
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.
I would suggest that you take a look at using NPOI library, it is very fast and works reliably on the server side. And you can then control where the file is generated.
If you are using a temp path or a temp file you should not care about where it is. If you need to care you should use a concrete path with a concrete file. You can also use a MemoryStream to do this all without HardDisk.
EDIT:
Additional to the comment I recommend you to use Open XML to create a Excel Sheet. If this is an option let me know than will I post more on that.
I must say I didn't know this article from Chris Taylors post and if I had found this one last year it had saved me a lot of time. But what I must say at this point; it is possible to get a serverside solution running which uses interop and I need it last year. But it was a pain till it work and if anyone want to give it a try here are some advices:
you should not use interop directly
from a ASP apllication
you can't use impersonation (it may
fail unexpected)
you will need a service which runs as
System
you need a executable that runs the
interop
you have to manage the the execution
through the service (and I mean
manage, not just starting)
And again; I don't recommend to do this. Use any other solution if you. (MS Supports automation services with SharePoint2010)
is there a way to notify user about a new version of plugin available?
This can be certainly done by writing some custom code to ping webservice, finding status and based on that displaying message, but then i am wondering if there is a predefined way/template available which can be used and achieved.
If you are sharing sample code, I like C#.
I think one of the best ways to achieve this without writing your own custom code is to use ClickOnce (or a ClickOnce alternative) - "ClickOnce applications can be self-updating; they can check for newer versions as they become available and automatically replace any updated files."
ClickOnce can be and is often used in conjunction with Office addins - for example, see http://robindotnet.wordpress.com/2010/07/11/how-do-i-programmatically-find-the-deployed-files-for-a-vsto-add-in/
Also, another question regarding open-source options to Click-Once might be a good idea - clickonce - what is a good open source alternative to clickonce? (DDay.Update)?
I work for a company that develops a CRM tool and offers integration with MS Office(2003 & 2007) from windows XP to 7. (I'm working using Win7)
My task is to call an Outlook instance (using C#) from this CRM tool when the user wants to send an email and prepopulate with data of the CRM tool (email, recipient, etc..)
All of this already works just fine.
The problem I'm having is that Outlook's "object model guard" is throwing com Exception
(Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT)))
the moment I try to read a protected value from the mailItem (such as mail.bodyHTML).
Example Snippet:
using MSOutlook = Microsoft.Office.Interop.Outlook;
//untrusted Instance
_outlook = new MSOutlook.Application();
MSOutlook.MailItem mail = (MSOutlook.MailItem)_outlook.CreateItem(MSOutlook.OlItemType.olMailItem);
//this where the Exception occurs
string outlookStdHTMLBody = mail.HTMLBody;
I've done quite a bit of reading and know that my Outlook Instance (derived by using new Application) is considered untrusted and therefore the "omg" kicks in.
I do have a workaround for development:
I'm running VS2010 as Administrator and if I run Outlook as Administrator as well - all is good. I suppose this is due to them having the same integrity levels(high) and the UAC(?) is not complaining. But that just ain't the way to go for deployment.
Now the question is:
Is there a way to obtain a trusted instance of Outlook so that I can avoid this exception?
I've already read that when developing an Office Add-In using VSTO one can obtain a trusted Instance from the OnComplete event and/or using "ThisAddin"
But I "merely" want to start an outlook instance and preopulate it, and do not want to develop an Add-In since this is not the requirement.
And to make it clear - I have no problem with pop ups informing the user that outlook is being accessed - I just want to get rid of the exception!
So how can I get around this problem using code?
Any help is highly appreciated!
Thomas
Take a look at Dimitry's Redemption Lib, It was designed to do exacly this.
Well,
I've already spent way too much time and energy on this question so I think I came up with a pragmatic workaround for my particular case - but no real solution!
The problem is apparently due to the programms running at different integrity levels (Outlook = medium, VS2010 = admin or high). Office runs by default on a medium level and so will my future application once deployed. So there shouldn't be any trouble, since if the CRM and Outlook run at the same level, there's no problem.
For development I just let em both run on high, or medium (starting my compiled files from the debug folder).
In any other case a Messagebox warning is shown informing the user of the different integrity levels that cause an exception and prevent access.
At the code level, when I try to read any (by Outlook) prepolutated, protected properties and the object model guard raises the exception, I just catch it and use default values instead.
Why I had to read them in first place is currently beyond me - but so were the specs which were handed to me.
Anyway thanks for reading and if I ever come up with a solution I'll be sure to psot it - until then keep in mind that a pragmatic solution is better then none!
Happy Father's Day everyone!