Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-10-12
9
Medium Priority
?
883 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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 750 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

705 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