WebBrowser (loop automation) - Cesa

24-Sep-07 02:54:00
Hello,

Background information ….

I have a VS2005 C# Windows forms app which has several text fields, one
button control and one webbrowser control that I use to display an external
webpage and based on the input data provided by the user, I perform some
tasks on the webpage. The idea is to go automatically go through several web
pages based in data captured by the user until I reach to a desired webpage.

All this works fine,
The user fills the data on the windows form, then clicks on the form's
button and the process starts.
The click method of this button does something like like …

private void btnSendData_Click(object sender, EventArgs e)
{

Uri myUri = new Uri (http://www.externalwebsite/page1.htm);
this.myWebBrowser.Url = myUri;
this.stageSecuence = 1;

}

I use a variable named "stageSecuence" in the next method to perform some
automated tasks depending on the webpage that is being processed.

Then for the webbrowser control I have the following method:

private void myWebBrowser_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)
{

switch (this.stageSecuence)
{
case 1:
// perform some tasks like invoking the submit on the web page
this.stageSecuence++;
case 2:
// perform some other tasks
this.stageSecuence++;

// and so on

}

Current situation,

Now, instead of executing this automation on the webpage based on the data
manually typed by the user; I want to call this process several times based
on  some database information.
I wrote the following code to perfom a loop (hoping to call sereval times
the automation process)

for (int i = 0; i < this.numberOfTableRecords; i++)
{
// get record info

Uri myUri = new Uri (http://www.externalwebsite/page1.htm);
this.myWebBrowser.Url = myUri;
this.stageSecuence = 1;
}

By doing this I only get the myWebBrowser_DocumentCompleted method executed
only once for the last record of the loop; in fact this method is executed
once the loop has finished.

How can I get the DocumentCompleted method executed once for every record in
the loop ?
Can I call this method manually such as:
this.myWebBrowser_DocumentCompleted( … ) ??

Thanks in advance,
Cesar
reply
 
 

WebBrowser (loop automation) - Robbe Morris - [MVP] C#

27-Sep-07 09:27:29
You have to set up an event driven "loop" if you will.
You won't be able to use a for loop.

Essentially, you'll have class level private variables that hold
the page you are on and an array of pages you need to process.

You write a method that processes the steps.  When the user
hits a button, you fire step 1.  Then, in the document complete
event, you determine the page just processed and call the method
to process the next page.  You let the document complete event
drive the process not your for loop.

You could get fancier than this of course but it should suffice.

I wrote something like this to auto submit letters to ever member
of congress through their own individual web sites and custom
authentication schemes.

--
Robbe Morris [Microsoft MVP - Visual C#]
.NET PropertyGrid Control - ListBox, ComboBox, and Custom Classes
http://www.eggheadcafe.com/tutorials/aspnet/270e9432-d236-47e7-b1af-5cd3abe27a75/net-propertygrid-control.aspx
reply
 
Word 2007 symbols problem
promotion
Silverlight    WPF    WCF    WWF    LINQ   
JavaScript    AJAX    ASP.NET    XAML   
C#    VB.NET    VB 6.0    GDI+    IIS    XML   
.NET Generics    Anonymous Methods    Delegate   
Visual Studio .NET    Expression Blend    Virus   
Windows Vista    Windows XP    Windows Update   
Windows 2003 Server    Windows 2008 Server   
SQL Server    Microsoft Excel    Microsoft Word   
SharePoint    BizTalk    Virtual Earth   
.NET Compact Framework    Web Service   

"Everything" RSS / ATOM Feed Parser
How to send and receive messages through message queuing in .Net
How to Read text file as database
SQL Server 2005 Paging Performance Tip
Display code of web page.
Fully Scalable Excel File Importer class for .net using Microsoft Jet driver
Generic Chart Color Manager class that can be used for any charts
Helper class to style the infragistics wingrid
Using Reflection to detemine as Assembly Info in and out.
Helper class to play with Window (Owners and position)
Resolving displayname from the culture using the XmlLanguage and LanguageSpecificStringDictionary class