I'm really hoping (and expecting, to be honest) that I've made some simple mistake here, so please accept my apologies if this seems a little dim...
Trying to build a little c# app that retrieves a dataset from a database (not a problem so far), and for each row, creates an infopath form that can then be emailed to a user for completion. To that purpose, I've added references to the two Interops I can find: Microsoft.Office.Interop.InfoPath.dll (runtime v1.1.4322) & Microsoft.Office.Interop.InfoPath.Xml.dll (also runtime v1.1.4322)
I've designed the infopath template form, and saved the .XSN to disk with the intent that my c# app can use it to create a new XDocument for an InfoPathApplication object.
The code I'm attempting to use is as below:
Microsoft.Office.Interop.InfoPath.Application infoPathApp = new Microsoft.Office.Interop.InfoPath.Application();
object ob_svr;
XDocument x_svr;
try
{
infoPathApp.XDocuments.NewFromSolution("C:\\obj\\TestWallchartDB.xsn");
//ob_svr = infoPathApp.XDocuments.NewFromSolution("C:\\obj\\TestWallchartDB.xsn");
//x_svr = (XDocument) infoPathApp.XDocuments.NewFromSolution("C:\\obj\\TestWallchartDB.xsn");
}
catch (Exception ex)
{
/*Unable to cast COM object of type 'Microsoft.Office.Interop.InfoPath.XDocumentsCollectionClass'
*to interface type 'Microsoft.Office.Interop.InfoPath.XDocuments2'. This operation failed because the
*QueryInterface call on the COM component for the interface with IID '{096CD647-0786-11D1-95FA-0080C78EE3BB}'
*failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
*/
throw;
}
With any of the three calls to the NewFromSolution method, I get the same 'unable to cast' exception. I've seen a fair few examples in these and other forums of people using the method from within Wallchart, so is it simply that I can't use the method from an external application?
Many thanks in advance for thoughts