axWebBrowser1.Navigate Auto Page Loader In A Real Browser

Here's a quick snippet demonstrating how to read in a text file list of urls in order to automatically browse to each one every 3 seconds. There are other automated ways of performing this task. This one guarantees the server sees your request as a true browser and let's you watch the process or track failures. You could also expand on this and auto populate form values. See: http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=967

private int CurIndex = 0;
private System.Windows.Forms.Button button1;
private ArrayList MyFiles = new ArrayList();

private void ProcessUrl()
{

string FileName="";
object o = System.Reflection.Missing.Value;

try
{

if (CurIndex == 0)
{
this.timer1.Enabled = false;
CurIndex = 0;
return;
}

FileName = MyFiles[CurIndex].ToString().Trim();

if (FileName.Length > 0)
{
this.axWebBrowser1.Navigate(FileName,ref o,ref o,ref o,ref o);
Application.DoEvents();
this.textBox1.Text = FileName;
}

}
catch (Exception) { throw; }
finally
{
CurIndex--;
this.textBox4.Text = CurIndex.ToString() + " of " + MyFiles.Count.ToString();
}

}

private void button1_Click(object sender, System.EventArgs e)
{

Hourglass(true);

using(StreamReader sr = new StreamReader("C:\temp\filelist.txt"))
{

MyFiles.Clear();

while (sr.Peek() >=0)
{
MyFiles.Add(sr.ReadLine());
}

sr.Close();

}

Hourglass(false);
Application.DoEvents();
CurIndex = MyFiles.Count;

this.timer1.Enabled = true;

}

private void timer1_Tick(object sender, System.EventArgs e)
{
Hourglass(true);
ProcessUrl();
Hourglass(false);
Application.DoEvents();
}

public static void Hourglass(bool Show)
{
if (Show == true)
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
}
else
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
}
return;
}


Submission Date:  9/24/2005 9:01:05 AM
Submitted By:  Robbe Morris
My Home Page:  http://www.robbemorris.com

By Robbe Morris   Popularity  (1012 Views)
Picture
Biography - Robbe Morris
Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of NullSkull.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.  Robbe also loves to scuba dive and go deep sea fishing in the Florida Keys or off the coast of Daytona Beach. Microsoft MVP
Here's my most recent course on Pluralsight. I think it has some interesting insight on IT professional job interviews and using words in your resume to influence the questions you'll be asked. Resumes, Job Seeking, and Interviews in context.