<li>访问量:<asp:Literal ID="ltlVistorNum" runat="server"></asp:Literal></li>
using System;
using System.Xml;
using System.IO;
public partial class Controls_Footer : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string vistorNumFile = Server.MapPath("~/") + "vistorNum.xml";
XmlDocument xmldoc = new XmlDocument();
try
{
if (!File.Exists(vistorNumFile))
{
xmldoc.AppendChild(xmldoc.CreateXmlDeclaration("1.0", "UTF-8", null));
XmlElement firstElement = xmldoc.CreateElement("", "data", "");
xmldoc.AppendChild(firstElement);
XmlElement secondElement = xmldoc.CreateElement("vistorNumber");
secondElement.InnerText = "8000500";
firstElement.AppendChild(secondElement);
ltlVistorNum.Text = secondElement.InnerText;
}
else
{
xmldoc.Load(vistorNumFile);//xmlPath为xml文件路径
XmlNode xmlNode = xmldoc.SelectSingleNode("/data/vistorNumber");
xmlNode.InnerText = (Convert.ToInt32(xmlNode.InnerText) + 1) + "";
ltlVistorNum.Text = xmlNode.InnerText;
}
xmldoc.Save(vistorNumFile);
}
catch
{
ltlVistorNum.Text = "8000000";
}
finally
{
xmldoc = null;
}
}
}
}