Hopefully you may be able to help me, I have got a random image reading from a file and it sends it to the screen fine, but is there a way to do it through CSS?
Here is the code I have so far.
VB CODE
Imports System.IO
Partial Class ImagesFromDirectory
Inherits System.Web.UI.MasterPage
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
'Programmatically pick a random image from the ~/Images directory
HeaderImage.ImageUrl = PickImageFromDirectory("~/Images/Image")
End If
End Sub
'Returns the virtual path to a randomly-selected image in the specified directory
Private Function PickImageFromDirectory(ByVal directoryPath As String) As String
Dim dirInfo As New DirectoryInfo(Server.MapPath(directoryPath))
Dim fileList() As FileInfo = dirInfo.GetFiles()
Dim numberOfFiles As Integer = fileList.Length
'Pick a random image from the list
Dim rnd As New Random
Dim randomFileIndex As Integer = rnd.Next(numberOfFiles)
Dim imageFileName As String = fileList(randomFileIndex).Name
Dim fullImageFileName As String = Path.Combine(directoryPath, imageFileName)
Return fullImageFileName
End Function
End Class
In file to display to page
<asp:Image ID="HeaderImage" alt="Main Page Image" title="Main Page Image" runat="server" />
all help would be greatful.
cheers
Dave

New Topic/Question
Reply




MultiQuote



|