Hello
I'm using a webbrowser control to get the source of the html page which has different
iframes. I'm using the click events to get to a certain html page frame and then parse it to
create an xml file
Here is the problem. The setup project I create when installed on a machine having only .net
framework doesn't work correctly. It doesn't automatically execute the click events and
create the xml file
When I run the same code on a machine having VS.NET installed, those events get triggered
correctly
Here is the code which I'm trying to use
I would appreciate your help in analyzing why this won't work on machines having only .net
framework. I have looked into documentation on the msdn website as well as other newsgroups
with no specific clues to solve this problem
using System
using System.Drawing
using System.Collections
using System.ComponentModel
using System.Windows.Forms
using System.IO
using XYZcomp
using mshtml
using System.Runtime.InteropServices
namespace XYZcom
public class getXMLData : System.Windows.Forms.For
private AxSHDocVw.AxWebBrowser axWebXYZcomp
private System.Windows.Forms.Button btnCancel
private System.Windows.Forms.Button btnGetCtfrmData
private System.ComponentModel.Container components = null
public getXMLData(
/
// Required for Windows Form Designer suppor
/
InitializeComponent()
/
// TODO: Add any constructor code after InitializeComponent cal
/
//Variable Declaration
string strAppName = "XYZcomp";//application nam
string URL1; //to assign the first URL under which a click event has to fire
on an element
string URL2; //to assign the 2nd URL under which a click event has to fire
on an element
bool bolclick1 =false;
bool bolclick2 = false
// Clean up any resources being used
protected override void Dispose( bool disposing
if( disposing
if (components != null)
components.Dispose()
base.Dispose( disposing )
#region Windows Form Designer generated cod
// Required method for Designer support - do not modif
// the contents of this method with the code editor
private void InitializeComponent(
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(getXMLData))
this.axWebXYZcomp = new AxSHDocVw.AxWebBrowser()
this.btnCancel = new System.Windows.Forms.Button()
this.btnGetCtfrmData = new System.Windows.Forms.Button()
((System.ComponentModel.ISupportInitialize)(this.axWebXYZcomp)).BeginInit()
this.SuspendLayout()
//
// axWebXYZcom
//
this.axWebXYZcomp.Enabled = true
this.axWebXYZcomp.Location = new System.Drawing.Point(24, 64)
this.axWebXYZcomp.OcxState =
((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebXYZcomp.OcxState")))
this.axWebXYZcomp.Size = new System.Drawing.Size(952, 608)
this.axWebXYZcomp.TabIndex = 0
this.axWebXYZcomp.DownloadComplete += new
System.EventHandler(this.axWebXYZcomp_DownloadComplete)
this.axWebXYZcomp.NavigateComplete2 += new
AxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(this.axWebXYZcomp_NavigateComple
e2)
this.axWebXYZcomp.DocumentComplete += new
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(this.axWebXYZcomp_DocumentComplet
)
//
// btnCance
//
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat
this.btnCancel.Font = new System.Drawing.Font("Arial", 9F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)))
this.btnCancel.Location = new System.Drawing.Point(888, 16)
this.btnCancel.Name = "btnCancel"
this.btnCancel.Size = new System.Drawing.Size(88, 24)
this.btnCancel.TabIndex = 4
this.btnCancel.Text = "Cancel"
this.btnCancel.Click += new
System.EventHandler(this.btnCancel_Click)
//
// btnGetCtfrmDat
//
this.btnGetCtfrmData.FlatStyle =
System.Windows.Forms.FlatStyle.Flat
this.btnGetCtfrmData.Font = new System.Drawing.Font("Arial", 9F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnGetCtfrmData.Location = new System.Drawing.Point(680, 16);
this.btnGetCtfrmData.Name = "btnGetCtfrmData";
this.btnGetCtfrmData.Size = new System.Drawing.Size(176, 24);
this.btnGetCtfrmData.TabIndex = 3;
this.btnGetCtfrmData.Text = "Get Contract Form Data";
this.btnGetCtfrmData.Click += new
System.EventHandler(this.btnGetCtfrmData_Click);
//
// getXMLData
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(181)),
((System.Byte)(208)), ((System.Byte)(243)));
this.ClientSize = new System.Drawing.Size(1000, 693);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnCancel,
this.btnGetCtfrmData,
this.axWebXYZcomp});
this.Name = "getXMLData";
this.Text = "XYZcomp";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.getXMLData_Load);
((System.ComponentModel.ISupportInitialize)(this.axWebXYZcomp)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new getXMLData());
}
/// <summary>
/// Get Contract Form Data button Click event will navigate to
/// the "https://easy.XYZcomp.com/data" URL.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGetCtfrmData_Click(object sender, System.EventArgs e)
{
object URL ="https://easy.XYZcomp.com/data";
object o=null;
this.axWebXYZcomp.Navigate2(ref URL,ref o, ref o, ref o, ref o);
}
/// <summary>
/// DocumentComplete event of WebBrowser Control fires when a document has
been
/// completely loaded and initialized. The Iframe(Contract Form) data is
saved to
/// the .htm document. Uses IHTMLDocument2 interface to get the source code.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void axWebXYZcomp_DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
try
{
if( (string)e.uRL ==
"https://easy.XYZcomp.com/data/show.asp?id=215&sid=&tst=4&bSize=1")
{
IHTMLDocument2 doc;
string appPath = Application.StartupPath;
string srcFileNam = "ContractFormData.htm";
string dstFileNam = "ContractFormData.xml";
object boxDoc = axWebXYZcomp.Document;
doc = (IHTMLDocument2)boxDoc;
object objFrameNam = "queueIframe";
object objFrame = doc.frames.item( ref objFrameNam
);
HTMLWindow2Class htmlFrameWin =
(HTMLWindow2Class)objFrame;
object objFrameDoc = htmlFrameWin.document;
HTMLDocumentClass htmlFrameDoc =
(HTMLDocumentClass)objFrameDoc;
foreach(IHTMLElement el in
(IHTMLElementCollection)htmlFrameDoc.all)
{
if(el.GetType().ToString().Trim().ToUpper()
== "mshtml.HTMLHtmlElementClass".ToUpper())
{
string strFrameSrc = el.outerHTML;
genXMLData objWriter = new
genXMLData();
bool blnTxt =
objWriter.WriteTotext(strFrameSrc,srcFileNam);
}
}
if(WriteXml(srcFileNam,dstFileNam))
{
MessageBox.Show("Exported the 'Contract Form
Data' to XML file at " + appPath + "\\" + dstFileNam + ".",strAppName);
}
}
}
catch(Exception d)
{
MessageBox.Show("Exception occurred. " + d.Source +
d.Message );
}
}
/// <summary>
/// Calling genXML method of genXMLData Class from XYZcomp Namespace to
generate the
/// Contract Form Data in XML file.
/// </summary>
/// <param name="srcFilePath">Source File name</param>
/// <param name="dstFilePath">Destination File Name</param>
/// <returns>Returns Bool value</returns>
private bool WriteXml(string srcFilePath,string dstFilePath)
{
genXMLData objWriter = new genXMLData();
bool result = objWriter.genXML(srcFilePath,dstFilePath);
return result;
}
/// <summary>
/// Assigning the Application name on Form Load event.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void getXMLData_Load(object sender, System.EventArgs e)
{
this.Text = strAppName;
}
/// <summary>
/// For exiting from the Application
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCancel_Click(object sender, System.EventArgs e)
{
DialogResult result;
result=MessageBox.Show(this,"Do you want to
exit?",strAppName,MessageBoxButtons.YesNo);
if(result==DialogResult.Yes)
{
this.Close();
}
}
/// <summary>
/// Fires after a navigation to a link is completed on either a window or
frameSet element.
/// Used to assign the URL under which links needs to be clicked.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void axWebXYZcomp_NavigateComplete2(object sender,
AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
if((string)e.uRL== "https://easy.XYZcomp.com/data/?HTTP_REFERER=")
Tim Anderson - 12 Apr 2004 23:43 GMT
> Hello,
> I'm using a webbrowser control to get the source of the html page which has different
[quoted text clipped - 5 lines]
> When I run the same code on a machine having VS.NET installed, those events get triggered
> correctly.
It might be because the mshtml PIA (primary interop assembly) does not get
installed by default with the .Net Framework runtime. It does get installed
with VS.Net. It is redistributable, so you can deploy it with your project.
The file is Microsoft.mshtml.dll.
Tim
Free htmleditor in C#:
http://www.itwriting.com/htmleditor/index.php
ej1001 - 13 Apr 2004 07:46 GMT
Thanks for the imd response. We are distributing the Microsoft.mshtml.dll with the setup. It is getting installed in the same directory where the application is getting installed. Also AxInterop.SHDocVw.dll and Interop.SHDocVw.dll are also getting installed on the system in the application directory.
Is it is required to install these dll's which are getting bundled with application needs to be installed in a specific path
or is there any other solution for this.
I found some of the solution given in this group like to use DispId . Why it needs to be done when .Net Framework takes care of everything related to Introp? Still looking out solution
thank
ej100
"Ying-Shen Yu[MSFT]" - 13 Apr 2004 13:24 GMT
Hi,
The code in your first post seems be truncated by newsgroup server, I
didn't see the rest part of the code. Could you send me a simple sample
with the html page to reproduce this problem?
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no
rights.This mail should not be replied directly, please remove the word
"online" before sending mail.
ej1001 - 13 Apr 2004 15:51 GMT
Hello
I am pasting only the relevant code down here. Our problem lies in
el.GetType().ToString().Trim().ToUpper()
This returns SYSTEM._COMOBJECT for all the elements in the HTMLELEMENT collection on the system where only .Net framework is installed. So it never satisfies the condition and el.click event is never getting fired.
Please help us to resolve this problem
IHTMLDocument2 doc;
object boxDoc = axWebTDCMobil.Document
doc = (IHTMLDocument2)boxDoc;
if(bolclick1==false
if(URL1=="https://url1"
foreach(IHTMLElement el in (IHTMLElementCollection)doc.body.all
{
if(el.GetType().ToString().Trim().ToUpper() == "mshtml.HTMLPhraseElementClass".ToUpper())
{
if(el.innerHTML=="status"
{
el.click()
bolclick1=true
}
"Ying-Shen Yu[MSFT]" - 14 Apr 2004 09:37 GMT
Hi,
How about using " is operator" instead of matching string?
<code>
foreach (IHTMLElement el in (IHTMLElementCollection)doc.body.all)
{
if (el is mshtml.IHTMLPhraseElement)
{
...
}
}
</code>
Is it helpful to resolve this problem?
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
ej1001 - 14 Apr 2004 12:46 GMT
Thanks a ton Ying-Shen Yu !
It works fine. But can I know why el.GetType does not work under .net framework environment when it works fine with VS.Net
Thanks once again... If you can give some inputs on the above issue it will be helpful
Best Regards
ej1001
"Ying-Shen Yu[MSFT]" - 15 Apr 2004 05:36 GMT
I'm not sure about the reason, I suspect the version of mshtml is not same
as the mshtml on your dev machine, so the some internal COM coclass is
different. In COM programming, we should check if it has a certain
interface rather than checking if it is a certain co-class.
Thanks!
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
ej1001 - 20 Apr 2004 18:21 GMT
When trying to use the web browser control from an ASP.NET web form,
it gives a 'page cannot be displayed' error
The previous application was a winforms application which used the webbrowser control inside it
When we tried to port this code over to a webform we are running into this problem
Is there any other way to do this using webforms and web browser control
The web browser control that we have, tries to get the source of the webpage that it is navigating to
We need the document object which is returned by the web browser control
Is there a particular way we need to approach this problem
Thanks
EJ
"Ying-Shen Yu[MSFT]" - 21 Apr 2004 10:34 GMT
Hi EJ,
Is there any error information when you debugging the ASP.NET server
application?
To my limited ASP.NET knowledge, I remember the worker thread in ASP.NET
are worked in MTA threading model, which might cause problem when creating
the ActiveX control(which is mostly used in STA model). Thinking this issue
is more related to ASP.NET, it would be better to also post your question
in group, microsoft.public.dotnet.framework.aspnet.
maybe the community members in that group can come up with some helpful
idea on it.
Thanks!
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
ej1001 - 22 Apr 2004 10:31 GMT
Thanks Ying-Shen Yu
We will respost the question in the forum u specified
Regards
EJ