Display Random Image From XML File


Sub btnName_Click(s As Object, e As EventArgs)

Dim xmlDoc As XmlDocument = New XmlDocument()

xmlDoc.Load(Server.MapPath("randomimage.xml"))

Dim mynodeList As XmlNodeList = xmlDoc.SelectNodes("images/item")

Dim nodecount As Integer = mynodeList.Count

Dim intRand As Integer

Dim Generator As System.Random = New System.Random()

intRand = Generator.Next(1, nodecount + 1)

Dim mynode As XmlNode = xmlDoc.SelectSingleNode(String.Format("images/item[guid='{0}']", intRand))

img1.src = mynode.ChildNodes(2).InnerText

imgfoc.Focus()

    End Sub
        

View XML file

Test it! Click the button below to display a random image: