Reputation: 519
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.
Upvotes: 3
Views: 196
Reputation: 1316
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();
Upvotes: 2