C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Interview   Jobs   Projects   Offshore Development    
Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Revenue Sharing | Talk to Us |



My Profile

Gifts

Active Members
TodayLast 7 Days more...







Displaying Random Images in an ASP.NET Web Page


Posted Date: 24 Mar 2008    Resource Type: Code Snippets    Category: Actove Directory

Posted By: rahul       Member Level: Gold
Rating:     Points: 10


The resource has not been reviewed by Editors yet. Readers are adviced to use their best judgement before accessing this resource.
This resource will be reviewed shortly.
If you think this resource contain inappropriate content, please report to webmaster.



Displaying Random Images in an ASP.NET Web Page



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/HeaderImages")
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





<img src="Images/HeaderImages/1000IslandLake.jpg" border="0" alt="1,000 Island Lake" width="100%" height="100%" />


<img src="Images/HeaderImages/HalfDome.jpg" border="0" alt="Half Dome" width="100%" height="100%" />


<img src="Images/HeaderImages/HumphreyMountain.jpg" border="0" alt="Mt. Humphrey" width="100%" height="100%" />


<img src="Images/HeaderImages/MarieLake.jpg" border="0" alt="Marie Lake" width="100%" height="100%" />


<img src="Images/HeaderImages/PiuteCreek.jpg" border="0" alt="Piute Creek" width="100%" height="100%" />




Protected Sub ContentRotator1_ContentCreated(ByVal sender As Object, ByVal e As skmContentRotator.ContentCreatedEventArgs) Handles ContentRotator1.ContentCreated
'Resolve image paths
e.ContentItem.Content = e.ContentItem.Content.Replace("~", Request.ApplicationPath)
End Sub






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)
You must Sign In to post a response.
Next Resource: How to hide a control using javascript
Previous Resource: what are the scopes of an assembly
Return to Discussion Resource Index
Post New Resource
Category: Actove Directory


Post resources and earn money!

Related Resources



Read TATA Nano reviews.
dotNet Slackers   BizTalk Adaptors    Web Design   Scripts
Are you waiting for engineering entrance result? Watch here for engineering entrance results.
it support

Contact Us    Privacy Policy    Terms Of Use