Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Casting Error on FileQueryConnection in Infopath 2013 Code

I've been working on an infopath form to migrate infopath 2007 to infopath 2013. To bind data to DropDownList controls FileQueryConnection has been used.

 // Retrieve the data connection bound to the Manager drop-down list box
 FileQueryConnection institutionConnection =(FileQueryConnection)DataConnections[ExternalUsersDC];
 // returned by the owssvr.dll with a filter on External Users of Institution
 institutionConnection.FileLocation = GetFileLocation(currentSite, externalUsersGuid, ExternalUserInstitution, institution);
 // Query the data connection to fill the Manager drop-down list box with items
 institutionConnection.Execute();

Here ExternalUsersDC is the name of the infopath connection file. GetFileLocation method gets the list physical location which works fine as expected.

Casting error occurs while trying to DataConnection to FileQueryConnection. Error message as follows;

Unable to cast object of type 'Microsoft.Office.InfoPath.Internal.SharePointListAdapterRWQueryAdapterHost' to type 'Microsoft.Office.InfoPath.FileQueryConnection

I searched everywhere to find a reason and failed. If someone has experience with this issue, please shed some light on my path.

like image 265
anbuj Avatar asked Jul 28 '26 18:07

anbuj


1 Answers

Try AS operator. It will try to cast to appropriate type.If Casting is not possible it will fail gracefully by returning NULL.

    FileQueryConnection institutionConnection =DataConnections[ExternalUsersDC] as FileQueryConnection;
 // returned by the owssvr.dll with a filter on External Users of Institution
 institutionConnection.FileLocation = GetFileLocation(currentSite, externalUsersGuid, ExternalUserInstitution, institution);
 // Query the data connection to fill the Manager drop-down list box with items
 institutionConnection.Execute();
like image 74
Aslam Jiffry Avatar answered Jul 30 '26 09:07

Aslam Jiffry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!