QuadComm e-commerce solutions
Home
Paypal

ASP Tip: Display a random file

When doing this web site I wanted to display certain random ads like the book selection that appears always in the right hand bar.

Every ad has its own file which contains the HTML code for the ad (image, description and a link). To display a random ad I use an include file that opens a random file and displays its content. The text files have the following format: number.txt (1.txt, 2.txt,...)

This is the include file used:

<%
Dim DispFile
Dim FileContent

Randomize
DispFile = Int(Rnd*10)+1 ' Number of files (where 10 is the total number of files)

Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
Set Instream = FileObject.OpenTextFile ("e:/inetpub/quadcomm/books/"&DispFile&".txt", 1, FALSE, FALSE)

FileContent = Instream.ReadAll

Response.Write (FileContent)
%>

Download the text file here.

The last step is to include the file wherever you want to display the file:

<!--#include file="randomfile.asp"-->

I hope you find this useful!

Author: Carlos Baez

You can also submit your own code examples. Just e-mail them.

Read the disclaimer.

Boost your sales with Web Marketing Today Premium Edition