Get random file

S

shapper

Hello,

I am displaying an image on a web site.
Is it possible to get a random file from a folder?

Thanks,
Miguel
 
E

Eliyahu Goldin

Sure. Use System.IO.DirectoryInfo.GetFiles to get the list of files, use
method of the Random class to generate a random number between 0 and the
count of the files and select from the file list the file with the generated
index.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Random Number 2
Random Record. Alternative. 6
Random Record 17
How to solve this problem? 2
Random Value 3
Random image 1
Random Extension 10
Random Order of IEnumerable 5

Top