A Practical Guide to SharePoint 2013

A Practical Guide to SharePoint 2013
A Practical Guide to SharePoint 2013 - Book by Saifullah Shafiq

Wednesday, November 12, 2008

InfoPath Error: Cannot cast 'DataConnections[]' (which has an actual type of .....

Error:
(FileSubmitConnection)DataConnections["Submit"]              Cannot cast 'DataConnections["Submit"]' (which has an actual type of 'Microsoft.Office.InfoPath.Server.DocumentLifetime.SubmitToHostConnectionHost') to 'Microsoft.Office.InfoPath.FileSubmitConnection'            Microsoft.Office.InfoPath.FileSubmitConnection
Have you seen this error before? It occurs if you try to submit form to a host but you use data connection of type "FileSubmitConnection". Here is the code:
FileSubmitConnection  connection = (FileSubmitConnection) (DataConnections[“Submit”]);
You can submit to the following locations:
1. Web service
2. Forms library
3. As an email message
4. To the hosting environment
The code above is meant for submitting to a forms library. In workflow forms, people submit task forms to a hosting environment and they forget to change the data connection type, that is when they get this error. It is important you use correct casting when submitting the form. To submit a form (task form) to hosting environment, you should use following code:
SubmitToHostConnection  connection = (SubmitToHostConnection) (DataConnections[“Submit”]);