How do you programmatically open an InfoPath 2007 file from a service?
I am trying to open an InfoPath 2007 file programmatically from a Windows Service, but I am getting the following error:
System.Runtime.InteropServices.COMException (0x80043000): InfoPath cannot open the following file: C: \ path \ datafile.xml. Insufficient storage space please complete this operation.
This file opens in the InfoPath designer. It also runs programmatically as a WinForms application. But when you try to start windows service it explodes.
I consulted with the mighty Google. The two main results that are returned are either XML malformed (not the reason, since the form is manually opened correctly) or do something about trying to access the database (which I am not doing).
Does anyone know how to do this? Are there installation permissions on the service?
Update:
As requested by Anders, here is the code. Please note that this may not be the exact code I was working on 6 months ago when I originally posted the question. Since then we have switched to using XtraReports as they are much easier to work with and have fewer of these critical bugs. However, I would like to resolve this question for anyone who comes in and might need an answer.
Microsoft.Office.Interop.InfoPath.Application infoApp = new Microsoft.Office.Interop.InfoPath.Application();
try
{
Microsoft.Office.Interop.InfoPath.XDocument xDoc = null;
xDoc = infoApp.XDocuments.Open(fileName, (int)Microsoft.Office.Interop.InfoPath.XdDocumentVersionMode.xdUseExistingVersion);
xDoc.PrintOut();
infoApp.XDocuments.Close(0);
}
catch (Exception ex)
{
//handle error here
}
finally
{
try
{
if (infoApp != null)
infoApp.Quit(false);
}
catch { }
}
source to share