D
Dan the Man
Hi!
I'm new to infopath and am trying to use C# managed code to programmatically
setup a Custom Task Pane whenever the context changes. My code is below. At
first, I had a problem compiling the code because C# could not recognize type
HTMLDocument. So, I added the mshtml.dll reference using c:/Program
Files/Microsoft.NET/Primary Interop Assemblies/Microsoft.mshtml.dll. The
problem successfully compiled but when I run the application, I get
"System.Security.SecurityException" when I try to access HTMLDocument! I
know I'm missing a step. Do I need to add the mshtml reference to my
infopath Form? What else could it be?
Dan
P.S. Here is the code:
[InfoPathEventHandler(EventType=InfoPathEventType.OnContextChange)]
public void OnContextChange(DocContextChangeEvent e)
{
if (e.Type == "ContextNode")
{
// Retrieve task pane object
TaskPane oTaskPane =
thisXDocument.View.Window.TaskPanes[0];
// Retrieve html object for task pane
// Now get the HTMLDocument
HTMLTaskPaneObject oHtmlPane = (HTMLTaskPaneObject)oTaskPane;
// This is where the exception occurs!!!!!
mshtml.IHTMLElementCollection oHtmlDoc =
oHtmlPane.HTMLDocument.all;
// Clear previous help topic from task pane
if (helpString != null)
((mshtml.IHTMLElement)
oHtmlDoc.item(helpString,null)).style.display="none";
// Display DIV statement having same ID as the context node name
((mshtml.IHTMLElement)
oHtmlDoc.item(e.Context.nodeName,null)).style.display="";
// Keep record of string displayed, so can later be cleared
helpString=e.Context.nodeName;
// XML Selection or Context has changed. Write code here to respond to the
changes.
return;
}
}
I'm new to infopath and am trying to use C# managed code to programmatically
setup a Custom Task Pane whenever the context changes. My code is below. At
first, I had a problem compiling the code because C# could not recognize type
HTMLDocument. So, I added the mshtml.dll reference using c:/Program
Files/Microsoft.NET/Primary Interop Assemblies/Microsoft.mshtml.dll. The
problem successfully compiled but when I run the application, I get
"System.Security.SecurityException" when I try to access HTMLDocument! I
know I'm missing a step. Do I need to add the mshtml reference to my
infopath Form? What else could it be?
Dan
P.S. Here is the code:
[InfoPathEventHandler(EventType=InfoPathEventType.OnContextChange)]
public void OnContextChange(DocContextChangeEvent e)
{
if (e.Type == "ContextNode")
{
// Retrieve task pane object
TaskPane oTaskPane =
thisXDocument.View.Window.TaskPanes[0];
// Retrieve html object for task pane
// Now get the HTMLDocument
HTMLTaskPaneObject oHtmlPane = (HTMLTaskPaneObject)oTaskPane;
// This is where the exception occurs!!!!!
mshtml.IHTMLElementCollection oHtmlDoc =
oHtmlPane.HTMLDocument.all;
// Clear previous help topic from task pane
if (helpString != null)
((mshtml.IHTMLElement)
oHtmlDoc.item(helpString,null)).style.display="none";
// Display DIV statement having same ID as the context node name
((mshtml.IHTMLElement)
oHtmlDoc.item(e.Context.nodeName,null)).style.display="";
// Keep record of string displayed, so can later be cleared
helpString=e.Context.nodeName;
// XML Selection or Context has changed. Write code here to respond to the
changes.
return;
}
}