Hi all,
I have a very specific situation:
- Tabbed WPF application where each tab can contain a view with an Infopath FormControl. When a tab is opened, it creates a FormControl and does NewFromTemplate with the specified infopath template location.
- Unsigned infopath document templates that are only used to collect data. On submit, the data is stored in a business entity and saved to the database. The application works fine when one tab is opened.
The problems start when I open a second tab, return to my original tab and try to do anything programmatically with the XmlForm. (like checking the IsDirty property)
After a while of debugging I found that the following debug "watch" changes each time a new Tab (and thus FormControl) is opened:
((Microsoft.Office.Interop.InfoPath.XDocumentClass)(Microsoft.Office.Interop.InfoPath.SemiTrust.InfoPathOMHelper.thisDoc))._XDocument3_URI
With the first tab it's "Form 1", when opening the second tab this jumps to "Form 2" It appears that the SemiTrust provider for infopath holds a reference to a "current" document and if you try to access the XmlForm of the FormControl that's not the current document, you get SecurityExceptions (see below)
Does anybody know what can be done about this?
- Somehow tell the infopath host which document is currently selected (I couldn't find anything like this in the documentation / samples)
- Use different infopath hosts (is that even possible) for each tab
The exception:
System.UnauthorizedAccessException was unhandled by user code
Message="Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
Source="Microsoft.Office.InfoPath.Client.Internal.Host"
StackTrace:
at Microsoft.Office.Interop.InfoPath.SemiTrust.ICLRExtensions.IsCrossDomainSafe(Object punkCallee)
at Microsoft.Office.Interop.InfoPath.SemiTrust.InfoPathWrapperHelper.CheckCrossDomainSafety(IServiceProvider serviceProviderCallee)
at Microsoft.Office.Interop.InfoPath.SemiTrust.XDocumentWrapper.get_IsDirty()
at Microsoft.Office.InfoPath.Internal.XmlFormHost.get_Dirty()
at Bdo.AuditTool.Main.v1.Controls.InfoPathViewerControl.FormEvents_ContextChanged(Object sender, ContextChangedEventArgs e) in C:\Qurius\Sources\BDO - Audit Tool\Source\VS.NET\Bdo.AuditTool\Bdo.AuditTool.Main.v1\Controls\InfoPathViewerControl.xaml.cs:line 314
at Microsoft.Office.InfoPath.Internal.FormEventsHost.OnContextChange(DocContextChangeEvent pEvent)
at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnContextChange(DocContextChangeEvent pEvent)
InnerException: