Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
5
Reply
display urls one by one in webbrowser in C#
adam gills
Sep 21 2016 1:24 AM
272
Reply
Dear sir ,
I faced an issue to open urls one by one from text file in webbrowser in windows application,
although every time ony one url is display in web browser.
so plz help me where is problems arises.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace demotimer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//WebBrowser wb = sender as WebBrowser;
FileStream fs = new FileStream("D:/Pawan_R&D/timer/demotimer/urls.txt", FileMode.Open, FileAccess.Read);
//StreamReader sr = new StreamReader(fs);
// webBrowser1.Navigate(sr);
//webBrowser1.ScriptErrorsSuppressed = true;
int counter = 0;
string line;
System.IO.StreamReader file =new System.IO.StreamReader("D:/Pawan_R&D/timer/demotimer/urls.txt");
List<string> list=new List<string>();
try
{
webBrowser1.ScriptErrorsSuppressed = true;
while ((line = file.ReadLine()) != null)
{
//Console.WriteLine(line);
// webBrowser1.Navigate(line);
list.Add(line);
counter++;
}
string[] arr = list.ToArray();
Array.Sort(arr);
int i = 0;
for (i = 0; i < 5; i++)
{
webBrowser1.Navigate(arr[i]);
}
file.Close();
//Console.ReadLine();
//foreach (string url in File.ReadAllLines("D:/Pawan_R&D/timer/demotimer/urls.txt"))
//{
// webBrowser1.Navigate(url);
// counter++;
//}
}
catch (Exception)
{
MessageBox.Show("Internet Connection not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
//this.Close();
}
}
private void Form1_Load(object sender, EventArgs e)
{
WebBrowser wb = new WebBrowser();
webBrowser1.ScriptErrorsSuppressed = true;
wb.AllowNavigation = true;
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
// wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser2_DocumentCompleted);
// wb.Navigate("http://www.google.com");
//timer1.Start();
}
// private void timer1_Tick(object sender, EventArgs e)
//{
//timer1.Interval = 5000;//5 sec
// timer1.Tick += new System.EventHandler(timer1_Tick);
// webBrowser1.Refresh();
//}
}
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
5
)
Next Recommended Forum
what is the benifits using jquery in mvc5?
TranscationScope type with file systems