Cast error in FileQueryConnection in Infopath 2013 doc

I am working on an infopath form to port infopath 2007 to infopath 2013. FileQueryConnection is used to bind data to DropDownList controls.

 // 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. The GetFileLocation method gets the physical location of the list, which works fine as expected.

Casting error occurs when trying to connect DataConnection to FileQueryConnection. The error message is as follows:

Cannot apply object of type 'Microsoft.Office.InfoPath.Internal.SharePointListAdapterRWQueryAdapterHost' to input 'Microsoft.Office.InfoPath.FileQueryConnection

I searched everywhere to find the reason and couldn't. If anyone has experience in this matter, please shed some light on my path.

+3


source to share


1 answer


Try the operator AS

. It will try to cast on the appropriate type. If casting is not possible, he will gracefully refuse, 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();

      

+2


source







All Articles