hi there masters of c# code
i bow to your hard work and knowledge
i am a beginner and i would be very gratefull for full explainations and not just code snippets
my target is to create a web browser app in c# which load a difffrent website on each runtime
the string i want to run is posted below
i have about 70 webistes i wish the app to load a diffrent one from the 70 each runtime
the other thing is i want a way to make it load a diffrent user agent also each time i have also a list of about 120 user agents
thank you very much
i will post how far i got below
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
webBrowser1.Navigate(http://www.anyweb.com, "_self", null, "User-Agent: Mozilla/4.0");
}
}
}
Loading
VulpesPosted Mar 6, 2012, 6:39 AM
Sam HobbsPosted Mar 6, 2012, 7:55 PM
If it were me, I would help you to understand better how to solve the problem yourself. I wil try to remember to get back to this later; I have other things to do now.
One thing I wanted to point out is that you were doing a very common beginner mistake. Your code was creating a new Random class many tines. Look at Vulpes's code; he creates the Random class only once.
james bradberyPosted Mar 6, 2012, 7:33 PM
but finally vulpes nailed it
i am now haveing issues with the cache of the page not refreshing content lol
but i will try to fix
super help super forum
james bradberyPosted Mar 6, 2012, 3:31 AM
also i got soem more examples from some other coders
i will post here if you guys can help me arrange into working code would be super
[code]
public List GetWebsiteUrls() urls = new List();
{
List
url.Add("http://a.b.c");
url.Add("http://a.c.c");
....
return urls;
}
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
static List
static Random random;
public Form1()
{
InitializeComponent();
if(urls == null)
{
urls = GetWebsiteUrls(); //Need to implement
random = new Random();
}
string url = urls[random.Next(urls.count)];
webBrowser1.Navigate(url, "_self", null, "User-Agent: Mozilla/4.0
}
}
}
Dictionary userAgent = new Dictionary();
userAgent.Add(0, "User-Agent: Mozilla/4.0");
userAgent.Add(0, "User-Agent: Chrome/14.0");
string user = userAgent[random.Next(userAgent.Count)];
webBrowser1.Navigate(url, "_self", null, user);
[/code]
SenthilkumarPosted Mar 6, 2012, 3:22 AM
Sam HobbsPosted Mar 6, 2012, 2:55 AM
Note that your question is actually two or more questions.
You can use the Random class in .Net to generate a random number. I have not used it myself but there are very many articles that describe its use.
Since you do not specify how the data is stored, it is difficult to suggest how to access it in a way that will help you.