Form validation in Infopath 2007 through a C# external program

E

educos

Hi,

I want to verify that a set of XML forms issued from an Infopath 2007
template respect all rules that has been defined in this template (because a
user can force saving a form even if it does not respect rules)

I do that by looping into all XML, loading the form in InfoPath and test the
Errors property of the XDocument...but problems occur when I try to access
the Errors property. Below is the code. Where am I wrong ?

using Mcrosoft.Office.Interop.Infopath
....
ApplicationClass app = new ApplicationClass();
XdDocumentVersionMode mode = XdDocumentVersionMode.xdCanOpenInReadOnlyMode;
int numMode = (int)mode; // =8
XDocument form = app.XDocuments.Open(@"MyForm.xml", numMode); // ==> ok, I
can see the form opened in Infopath
ErrorsCollection ec = form.Errors; // ==> "Invalid cast exception" !!!!
int countErrors = ec.Count;
app.Quit(false);

Thanks for your help

Regards.

Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top