简体   繁体   中英

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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM