Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question regarding

0 views
Skip to first unread message

ev

unread,
Dec 3, 2008, 12:11:02 PM12/3/08
to
My problem is not an error or syntax problem, but I am trying to understand
the best way to navigate pages using mshtml (and not the webBrowser control,
since I will be doing this from a Windows service). I have code that looks
similar to that listed below. The problem is with the 'el.click' code. It
works, but I don't know how to set up where the incoming response would be.
It doesn't appear to be coming back into any of my existing objects (ms or
doc). If I were to click on a button or link, I would like to load the next
page programmatically and use the object model to look for the tags I need.

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!

Igor Tandetnik

unread,
Dec 3, 2008, 12:47:58 PM12/3/08
to
ev <e...@discussions.microsoft.com> wrote:
> My problem is not an error or syntax problem, but I am trying to
> understand the best way to navigate pages using mshtml (and not the
> webBrowser control, since I will be doing this from a Windows
> service).

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


ev

unread,
Dec 3, 2008, 12:58:03 PM12/3/08
to
Is there a way I can navigate without using a visual control (webBrowser)? I
can definitely do what I need to in the webBrowser control, but I will be
running a Windows service and this might be a problem. My other alternative
is to use webrequest / webresponse, but then I will have to recreate each
form. Thanks again for your help. -e-

Igor Tandetnik

unread,
Dec 3, 2008, 3:16:26 PM12/3/08
to
ev <e...@discussions.microsoft.com> wrote:
> Is there a way I can navigate without using a visual control
> (webBrowser)?

You can host WebBrowser on a hidden window.

0 new messages