1,105,334 Community Members

random selection from list

Member Avatar
james1on1
Newbie Poster
9 posts since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            webBrowser1.Navigate("http://www.anyweb.com", "_self", null, "User-Agent: Mozilla/4.0");
        }
    }
}
Member Avatar
james1on1
Newbie Poster
9 posts since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

someone gave me this example could anyone help me fix this into working code?

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        static List<string> urls;
        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 
        }
    }
}
Member Avatar
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 557 [?]
Q&As Helped to Solve: 489 [?]
Skill Endorsements: 21 [?]
 
0
 

Try this way:

public partial class Form1 : Form
    {
        static List<string> urls;
        static Random random = new Random();
 
        public Form1()
        {
            InitializeComponent();
            if(urls ==  null)
            {
                urls = GetWebsiteUrls();  //Need to implement
            }
           
            string url = urls[random.Next(urls.count)];
            System.Diagnostics.Process.Start("iexplore.exe", url); //try using some other webbrowser too
        }
    }
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: