C# Infopath 2013代码中FileQueryConnection的强制转换错误
我一直在使用infopath表单将infopath 2007迁移到infopath 2013。 要将数据绑定到DropDownList控件,请使用FileQueryConnectionC# Infopath 2013代码中FileQueryConnection的强制转换错误,c#,sharepoint-2013,infopath2010,C#,Sharepoint 2013,Infopath2010,我一直在使用infopath表单将infopath 2007迁移到infopath 2013。 要将数据绑定到DropDownList控件,请使用FileQueryConnection // Retrieve the data connection bound to the Manager drop-down list box FileQueryConnection institutionConnection =(FileQueryConnection)DataConnections[Ext
// 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”
我到处寻找原因,结果失败了。如果有人有这方面的经验,请阐明我的道路 作为操作员尝试
。它将尝试强制转换为适当的类型。如果无法强制转换,它将通过返回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();
谢谢你的回答。当然,它返回null,我需要知道此对象或替代对象的正确转换方式。不能转换两个不同的对象(不是继承的)。例如,不能将整数强制转换为字符串。但可以将对象强制转换为字符串,因为字符串也是对象。因此,在强制转换之前,请确保FileQueryConnection是一种数据连接类型。如果不是这种情况,则无法强制转换。请参阅他们已完成强制转换FileQueryConnection myDataSource=(FileQueryConnection)(DataSources[“XMLFile”].QueryConnection);此强制转换还会引发相同的异常。@anbuj.Microsoft.Office.InfoPath.DataConnection类是Microsoft.Office.InfoPath.FileQueryConnection类的父级。在这种情况下,您可以直接强制转换为代码。但由于上述类的实现可能不同,因此此处抛出错误。您是否检查了所使用的上述类的版本。它是这些类的最新实现吗?。以下链接可能对您有所帮助。