Hi there,
There are many, many ways to do this. To give you an idea of a possible solution, try this:
1. File | New Web Site
2. In App_Data create a file called Sample.xml and add the following data:
Code:
<?xml version="1.0" encoding="utf-8"?>
<articles>
<article>
<title>Article 1</title>
<body>The body of the article goes here.</body>
</article>
<article>
<title>Article 2</title>
<body>The body of the article goes here.</body>
</article>
<article>
<title>Article 3</title>
<body>The body of the article goes here.</body>
</article>
<article>
<title>Article 4</title>
<body>The body of the article goes here.</body>
</article>
<article>
<title>Article 5</title>
<body>The body of the article goes here.</body>
</article>
<article>
<title>Article 6</title>
<body>The body of the article goes here.</body>
</article>
</articles>
3. Create a new Web Form called Timer and add the following code:
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Timer.aspx.cs" Inherits="Timer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label" />
<asp:Timer ID="Timer1" runat="server" Interval="2000" ontick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
4. In the Code Behind, add the following Tick method:
Code:
protected void Timer1_Tick(object sender, EventArgs e)
{
int counter = 0;
object counterFromViewState = ViewState["Counter"];
if (counterFromViewState != null)
{
counter = Convert.ToInt32(counterFromViewState);
}
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("~/App_Data/sample.xml"));
var nodes = doc.SelectNodes("//articles/article");
if (nodes.Count <= counter)
{
counter = 0;
}
var nodeTitle = nodes[counter].SelectSingleNode("title").InnerText;
counter++;
ViewState["Counter"] = counter;
Label1.Text = nodeTitle;
}
This code reads in the data from the XML file using an XmlDocument. It keeps track of the zero based index of each "article" in the XML file in ViewState. It then gets this item from the XML file, retrieves its title and assigns that to the Label. The next time the timer ticks, the value of the counter is one more than large time, giving you the next record. When the counter gets bigger than the number of available records, it gets set back to 0.
You should see this as an example, and not production ready code. You may want to add caching (to avoid using loading the XML file on each tick), and add error handling.
For more information:
https://www.google.com/#sclient=psy-...=1050&bih=1234
https://www.google.com/#sclient=psy-...=1050&bih=1234
Cheers,
Imar