private void button1_Click(object sender, RoutedEventArgs e)
{
ShellWindows shellwindows = new ShellWindows();
string filename;
foreach (InternetExplorer ie in shellwindows)
{
// Get the document
mshtml.IHTMLDocument document = ((mshtml.IHTMLDocument)ie.Document);
// Get the script object.
object script = document.Script;
filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.Equals("iexplore") && ie.Document.parentWindow.name = "Test")
{
// Make the call:
string selectedColour = listBox1.SelectedValue.ToString();
ListBoxItem lbi = (listBox1.SelectedItem as ListBoxItem);
string[] colour = new string[] { lbi.Content.ToString() };
script.GetType().InvokeMember("setBackgroundColour", BindingFlags.InvokeMethod, null, script, colour);
// Release the script object, and possibly the document object.
Marshal.ReleaseComObject(script);
}
}
Hi,
I am trying to call a javascript funtion on a webpage from a winform application. The above code works in .NET 4.0 but in 3.5 the line
object script = document.Script;
throws a "Specified cast is not valid." exception!
Any thoughts? I dont think anything I am using is .Net 4.0 specific?
Many Thanks