Note that the pages are fairly complicated and I would prefer not to have to
recreate the form data and repost it with a WebRequest, but in general I am
open to alternatives that can be used in a Windows service.
IHTMLElementCollection c;
HTMLInputElementClass el;
// Load the main page.
WebClient client = new WebClient();
byte[] data = client.DownloadData(@"http://www.someurl.com");
HTMLDocumentClass ms = new mshtml.HTMLDocumentClass();
string strHTML = Encoding.ASCII.GetString(data);
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)ms;
doc.write(strHTML);
// Search for the item.
c = (IHTMLElementCollection)ms.getElementsByTagName("input");
for (int i = 0; i < c.length; i++)
{
el = (HTMLInputElementClass)c.item(i, 0);
try
{
if ((el.tagName.ToLower() == "input") &&
(el.type.ToLower() == "submit"))
{
el = (mshtml.HTMLInputElementClass)c.item(i, 0);
el.click();
continue;
}
}
catch(Exception ex)
{
// Add some error handling.
System.Diagnostics.Debug.Print(ex.Message);
continue;
}
}
Thanks in advance!
You can't navigate using MSHTML alone - that's precisely the service
that WebBrowser adds above and beyond what MSHTML can do.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
You can host WebBrowser on a hidden window.