I have been trying for couple of days to display random image, with no success. The code rotates the images in folder < /images > , but always displaying the source location, look here:
Below you will find the code I have been playing with. Appreciate your cooperation..:)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace asp34_CasinoMegaChallenge
{
public partial class asp34 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GetFiles();
}
public string GetFiles()
{
Random random = new Random();
string[] randomImages=Directory.GetFiles(HttpContext.Current.Server.MapPath("~/Images/"));
Image1.ImageUrl = randomImages[random.Next(randomImages.Length)];
return Image1.ImageUrl;
}
}
}