Code snippets
There are so many great resources out there for people who are learning to do Web design and don’t know where to start. I’ve listed a few of my favorites in the links section and I will expand this list as I find the time and the sites.
I thought that I would put my own little bit of information out there for all you just trying to find that perfect way to generate a random image. It’s an asp.net page that will look at all the images in a file and then display a random picture. Pretty cool. This is the effect that is used on the homepage to rotate through a bunch of images.
Here’s the code
<%@ Import Namespace=”System.IO” %>
<%@ Import Namespace=”System.Drawing” %>
<%@ Import Namespace=”System.Drawing.Imaging” %>
<html>
<head>
<title>Image Rotator</title>
<script language=”C#” runat=”server”>
public void Page_Load(object sender, System.EventArgs e) {
//TODO: if an specific image is passed in we should just show that image
string image = Request.QueryString["img"];
System.Drawing.Image img = null;
if(image ==null) {
//array of filenames
string[] filesjpg;
//get all the picture files in the same directory as rotate.aspx
filesjpg = Directory.GetFiles(Server.MapPath(“.”),”*.jpg”);
//get a new Random generator salted with the current second
Random r = new Random(DateTime.Now.Second);
//get an index into the filesjpg array a max = length of the file
int index = r.Next(filesjpg.Length);
//creamte a system.drawing.image object from the selected file
img = System.Drawing.Image.FromFile(filesjpg[index]);
}
else{
img = System.Drawing.Image.FromFile(Server.MapPath(image));
}
//save the object to the Response stream
img.Save(Response.OutputStream,img.RawFormat);
//Flush the output
Response.Flush();
//Clean Up
img.Dispose();
}
</script>
</head>
<body>
</body>
</html>
Search
Archives
Stuff Dan Likes
This text is not inteneded to be seen. Rather, it is junk text to force themes with auto widths to extend to there full measures. This text is not inteneded to be seen. Rather, it is junk text to force themes with auto widths to extend to there full measures. This text is not inteneded to be seen. Rather, it is junk text to force themes with auto widths to extend to there full measures.
Stuff Tammy Likes
This text is not inteneded to be seen. Rather, it is junk text to force themes with auto widths to extend to there full measures. This text is not inteneded to be seen. Rather, it is junk text to force themes with auto widths to extend to there full measures. This text is not inteneded to be seen. Rather, it is junk text to force themes with auto widths to extend to there full measures.









