473,594 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question on automating IE using mshtml and frame

Folks, I have a simple web page with frames. I am trying to automate
internet explorer to display the page and allow access to its frames.

Here is the sample code :

using mshtml;
static void Main(string[] args)

{

SHDocVw.Interne tExplorer explorer = null;

explorer = new InternetExplore r();
object nada = null;

explorer.Naviga te("file://" + "c:\\temp\\ xx" + "/frame.htm", ref nada, ref
nada, ref nada, ref nada);

explorer.Visibl e = true;

IWebBrowser2 browser;

browser = (IWebBrowser2)e xplorer;
IHTMLDocument2 doc = (IHTMLDocument2 )browser.Docume nt;

FramesCollectio n frames = (FramesCollecti on) doc.frames; // <<<======
exception

}

The browser launches and shows the page. Here is the web page:

<html>

<head>

<title>Title of page</title>

</head>

<frameset id="top" rows="25%,15%,1 5%,15%,15%,15%" >

<frame id="a" >

<frame id="b" >

<frame id="c" >

<frame id="d" >

<frame id="e" >

<frame id="f" >

</frameset>

</html>

The frames field of the doc variable when accessed is throwing an invalid
cast exception.

Obviously, I have done something wrong. Can someone advise?

thanks,

bob


Apr 9 '06 #1
2 4498
Hi Bob,

You can get a reference to your frame window like this:

int frameIndex = 0;
indexObj = i; // item() param must be a reference to an object
mshtml.IHTMLWin dow2 frame = (mshtml.IHTMLWi ndow2)doc.frame s.item(ref
indexObj);

If you need to find a frame by its name, loop through frames and check
the frame.name property until it matches what you're looking for.
Unfortunately the frames collection isn't enumerable, so you'll have to
use a "for" loop and frames.length.

HTH,

Chris

Apr 9 '06 #2
Hi Chris. Thanks for the reply. I found my problem. The application is a
console mode app and I "forgot" to mark the main thread with STAThread
attribute. Once I did that and wait for the doc load event the frames were
accessible with no exception.
Sorry for my late night flub.
bob

"Chris Fulstow" <ch**********@h otmail.com> wrote in message
news:11******** **************@ g10g2000cwb.goo glegroups.com.. .
Hi Bob,

You can get a reference to your frame window like this:

int frameIndex = 0;
indexObj = i; // item() param must be a reference to an object
mshtml.IHTMLWin dow2 frame = (mshtml.IHTMLWi ndow2)doc.frame s.item(ref
indexObj);

If you need to find a frame by its name, loop through frames and check
the frame.name property until it matches what you're looking for.
Unfortunately the frames collection isn't enumerable, so you'll have to
use a "for" loop and frames.length.

HTH,

Chris

Apr 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6802
by: John | last post by:
I have some code that changes a PDF file in another frame using: parent.frame.document.location.href = "PDF File" This code works fine the first time it is called. But if a PDF file is in that frame and the code is called again IE gives me an error: "no such interface supported" I have used this code for the past 5 years and it has worked fine with
1
7355
by: Newsgroup Reader | last post by:
I'm trying to create a chat program, however I find it most of the time these days clients use HTML or some sort of markup language to render text on the screen. My question is how would I render HTML without using MSHTML/IE? I already have a feeling that I'll have to create my own control. How would I go on doing this? (I would like to be able to edit/select text in a WinForm) Maybe someone can point to ways of enhancing the RichText...
2
5632
by: Gil Schulmann | last post by:
Hi. I am trying to load an HTML file into htmlDoc using c#. I see that the document does not load, but I can not understand where am I wrong. Any help ? My Code: class CFileHandler{ public delegate void
3
2601
by: John | last post by:
Does anyone know how to simulate the right click "Save Target As" using MSHTML? I find that I can navigate through the LinksCollection on any given page but often these links are links to files (*.doc, *.xls etc). If I follow the link, it will open the document, but I am interested in saving it. Any ideas?
0
2229
by: Atara | last post by:
Our application was build with VS 2003. I have tried to run it on a computer with .Net 2.0 (but without .Net 1.1 , as it should be used) and I got the following error - System.InvalidCastException: Unable to cast COM object of type 'mshtml.HTMLBodyClass' to class type ''. COM components that enter the CLR and do not support IProvideClassInfo or that do not have any interop assembly registered will be wrapped in the __ComObject type....
1
4476
by: Sujoan | last post by:
Hi all.. I generated SHDocVw.dll and MSHTML.dll using aximp and tlbimp commands in the folder i created my application.But when i used it in my application like using SHDocVw;using MSHTML; and tried to use the IHTMLDocument2 interface, Igot a error like this: E:\Project X Semester\BHO\Sample Projects\Sample_BHO\BHO.cs(12): The type or namespace name 'MSHTML' could not be found (are you missing a using directive or an assembly reference?)
10
1946
by: mg | last post by:
I'm migrating from VB6 and have a question about using 'Using' and the best way to use it. Here is a example of a small bit of code: dbConx("open") Using CN Dim CMD As New OleDbCommand(sSQL, CN) Dim DR As OleDbDataReader = CMD.ExecuteReader()
0
1039
by: Vibhu | last post by:
Hi, I need to scrape aspx pages for data using MSHTML. I am fairly comfortable using MSHTML. I need to know as to how I can submit information to aspx pages and get the results.. Any help will be beneficial. Regards,
2
2077
by: durgaprasad2004 | last post by:
hi friends, i have to close one frame using another frame. first it create one frame. after modification when i click submit is must be close the old frame,but it is not closing plz help me regarding this. Thank you.
0
7946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7876
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8234
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5408
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3859
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2385
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1478
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.