Infopath 2013代码中FileQueryConnection的转换错误

本文关键字:转换 错误 FileQueryConnection 2013 代码 Infopath | 更新日期: 2023-09-27 18:06:22

我一直致力于将infopath 2007表单迁移到infopath 2013。为了将数据绑定到下拉列表控件,使用了FileQueryConnection。

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

这里ExternalUsersDC是infopath连接文件的名称。GetFileLocation方法获取列表的物理位置,如预期的那样正常工作。

尝试从DataConnection到FileQueryConnection时发生强制转换错误。错误信息如下;

无法强制转换类型为"Microsoft.Office.InfoPath.Internal"的对象。sharepointlistadapterwqueryadapterhost '到类型'Microsoft.Office.InfoPath.FileQueryConnection

我到处寻找原因,但没有找到。如果有人有这个问题的经验,请指点我的道路。

Infopath 2013代码中FileQueryConnection的转换错误

尝试AS操作符。它将尝试转换为适当的类型。如果不可能强制转换,它将通过返回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();