473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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.InternetExplorer explorer = null;

explorer = new InternetExplorer();
object nada = null;

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

explorer.Visible = true;

IWebBrowser2 browser;

browser = (IWebBrowser2)explorer;
IHTMLDocument2 doc = (IHTMLDocument2)browser.Document;

FramesCollection frames = (FramesCollection) 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%,15%,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 4488
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.IHTMLWindow2 frame = (mshtml.IHTMLWindow2)doc.frames.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**********@hotmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.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.IHTMLWindow2 frame = (mshtml.IHTMLWindow2)doc.frames.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
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...
1
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...
2
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{...
3
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...
0
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 - ...
1
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...
10
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,...
0
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...
2
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.