Monday, May 25, 2009

Display random Image from the folder

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;

protected void Page_Load(object sender, EventArgs e)
{
string display = getimage();
Image1.ImageUrl = Path.Combine("~/image", display);
Label1.Text = display;

}

private string getimage()
{
Random rnd = new Random();
string[] image = Directory.GetFiles(MapPath("~/image"), "*.jpg");
string display = image[rnd.Next(image.Length)];
return Path.GetFileName(display);
}

1 comments:

Anonymous said...

Really very useful and can u give any one mtd to insert and retrive img from sql server in a binary form.....

Post a Comment

plzz give the comment