Solved

How to use axWebBrowserto get the HTML source of the page in a frameset?

Posted on 2004-10-12
9
862 Views
Last Modified: 2007-12-19
Hello,

A multi-frame page contains 3 html pages: page A, page B and page C. I need to get the HTML source of page C. I tried to use AxSHDocVw.AxWebBrowser to do that:

mshtml.HTMLDocument htm = (mshtml.HTMLDocument)axWebBrowser1.Document;

I can get the frame count by "htm.frames.length".

But, while I tried to use "htm.frames(2).Document.documentElement.innerText" to get HTML source, it said "Cannot apply indexing with [] to an expression of type 'mshtml.FramesCollection'".

Can you help me to resolve it? I have spent many days on it.

Thanks,
Simon
0
Comment
Question by:cjchuang98
9 Comments
 
LVL 18

Expert Comment

by:armoghan
ID: 12295470
see this link may help, it is in C but can help you

http://www.kbalertz.com/kb_815727.aspx

I think you have to do something like
htm.frames.items(2).Document.documentElement.innerText

that is what seems to be from the C code
0
 

Author Comment

by:cjchuang98
ID: 12296136
I have tried "htm.frames.item(2).Document.documentElement.innerText;". But it said "The best overloaded method match for 'mshtml.IHTMLFramesCollection2.item(ref object)' has some invalid arguments".

Do you know any sample in C#.NET?

0
 
LVL 8

Expert Comment

by:tomvergote
ID: 12296198
"m.frames(2).Docu"

if you are using c#.NET collections are indicated using []
so if you are trying to reach the 3nd frame you would use .frames[2]

what you are trying is a method call?
0
 

Author Comment

by:cjchuang98
ID: 12296279
I have tried "htm.frames[2].Document.documentElement.innerText;". But it said "Cannot apply indexing with [] to an expression of type 'mshtml.FramesCollection'".

Any other method?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 18

Expert Comment

by:armoghan
ID: 12296403
try creating an Empty Object and send its reference
Object o = new Object ();
htm.frames.item(o).Document.documentElement.innerText

or if you some how can get all the items list
I could not get what __Box was in the article
0
 
LVL 18

Accepted Solution

by:
armoghan earned 250 total points
ID: 12297159
ok it took me some effort but I found it out



see this code i is increamented



                              HTMLDocument myDoc = new HTMLDocumentClass();
                              myDoc = (HTMLDocument) axWebBrowser1.Document;
                              FramesCollection c = myDoc.frames;
                              
                              Object o = i;
                              i++;
                              Object c1 =null;
                              
                              try
                              {
                                    c1 =  c.item(ref o);
                              }
                              catch(Exception ex)
                              {
                                    Console.WriteLine(ex.Message);
                              }
                              HTMLWindow2Class c2 = ((HTMLWindow2Class)c1);
                              
                              Console.WriteLine(((mshtml.IHTMLElement)(((mshtml.HTMLDocumentClass)(((mshtml.IHTMLDocument2)((c2.document))))).documentElement)).innerText);
0
 

Author Comment

by:cjchuang98
ID: 12304804
Hi armoghan,

Thanks for your help. Your code works.

The following are my code based on yours:
-------------------------------------------------------------------------------------------------
mshtml.HTMLDocument htm = (mshtml.HTMLDocument)axWebBrowser1.Document;
for (int m = 0; m < htm.frames.length; m++)
{
      Object myObj = m;
      mshtml.HTMLWindow2Class myPage1 = (mshtml.HTMLWindow2Class)htm.frames.item(ref myObj);
      mshtml.IHTMLDocument2 myPage2 = (mshtml.IHTMLDocument2)myPage1.document;
      mshtml.HTMLDocumentClass myPage3 = (mshtml.HTMLDocumentClass)myPage2;
      mshtml.IHTMLElement myPage4 = (mshtml.IHTMLElement)myPage3.documentElement;

      Console.WriteLine(myPage4.innerHTML);
}
-------------------------------------------------------------------------------------------------

But, are there any possible to reduce the conversion?
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12315692
Yes sure there would be. I have not checked
I used quick watch to find out the solution. which starts type casting unnecessarly..
There may be some properties which will be accessible without Type casting.
0
 
LVL 8

Expert Comment

by:bman9111
ID: 14032465
armoghan,

not sure if u are still around but how would this code be in vb.net:

ok it took me some effort but I found it out



see this code i is increamented



                         HTMLDocument myDoc = new HTMLDocumentClass();
                         myDoc = (HTMLDocument) axWebBrowser1.Document;
                         FramesCollection c = myDoc.frames;
                         
                         Object o = i;
                         i++;
                         Object c1 =null;
                         
                         try
                         {
                              c1 =  c.item(ref o);
                         }
                         catch(Exception ex)
                         {
                              Console.WriteLine(ex.Message);
                         }
                         HTMLWindow2Class c2 = ((HTMLWindow2Class)c1);
                         
                         Console.WriteLine(((mshtml.IHTMLElement)(((mshtml.HTMLDocumentClass)(((mshtml.IHTMLDocument2)((c2.document))))).documentElement)).innerText);
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now