blah blah blah is here! blah blah » Close

up0down
link

Hi!

I just want make easy program that give me random file (string to textbox). So.. Can you please help me, and tell me how to solve this problem?

Thanks!

DirectoryInfo DI = new DirectoryInfo("D:\\*****\\******\\");
FileInfo[] FI = DI.GetFiles();

foreach (FileInfo f in FI)
listView1.Items.Add(f.ToString());

listView1.View = View.List;

Random rand = new Random();

string n = FI[rand.Next(0, FI.Length)]; <<<--- ?!
textBox1.Text = n;

many thanks!

last answered one year ago

1 answers

up0down
link

Either of these should work:

string n = FI[rand.Next(0, FI.Length)].Name;
// or
string n = FI[rand.Next(0, FI.Length)].ToString();

Flop
0

Thanks for answer. It's works fine!

Feedback