How to test if a form is correct accordig to validation rules ?

E

educos

Hi,

I have a directory with some XML files that where saved by a template form
in InfoPath.
In this template I defined some rules (validation).
I want to write a little program in C# that open each XML file with Infopath
and verify that all rules are respected.
I tried these following lines:

using Microsoft.Office.Interop.InfoPath;
....
ApplicationClass app = new ApplicationClass();
XDocument form = app.XDocuments.Open(@"MyForm1.xml",
(int)XdDocumentVersionMode.xdCanOpenInReadOnlyMode);
ErrorsCollection ec = form.Errors;
int nCountErrors = ec.Count
app.Quit(false);

but, when I try to get the Errors property, I get "Invalid cast exception".

Any idea of this problem ?
Perhaps I am wrong in the way to do the thing, thanks for any others ideas.

Regards.

Eric.
 
S

Shiva (GGK Tech)

Hi,
Below the statement conversion is wrong in your code.

(int)XdDocumentVersionMode.xdCanOpenInReadOnlyMode);

Instead of above statement you can use the below one:

XdDocumentVersionMode versionMode =
XdDocumentVersionMode.xdCanOpenInReadOnlyMode);

Hope this helps you.
 
E

educos

Hi Shiva,

I am surprise of ths point..why this problem of conversion could explain the
"invalid cast exception" on the Errors property.

I changed my code like this...and have always the same problem:

ApplicationClass app = new ApplicationClass();
XdDocumentVersionMode mode = XdDocumentVersionMode.xdCanOpenInReadOnlyMode;
int numMode = (int)mode; // =8
XDocument form = app.XDocuments.Open(@"MyForm1.xml", numMode);
ErrorsCollection ec = form.Errors; // ==> 'Invalid cast exception'
int countErrors = ec.Count;
app.Quit(false);

Any other idea ?

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