Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / September 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
educos - 06 Sep 2007 23:38 GMT
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.
Shiva (GGK Tech) - 07 Sep 2007 08:22 GMT
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.

Signature

Shiva
http://www.ggktech.com

> Hi,
>
[quoted text clipped - 22 lines]
>
> Eric.
educos - 07 Sep 2007 15:04 GMT
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.
Signature

Cordialement.
Eric.

> Hi,
> Below the statement conversion is wrong in your code.
[quoted text clipped - 34 lines]
> >
> > Eric.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.