Page Hit counter asp.net,c#

March 16, 2010 at 9:53 am 1 comment

.cs page

protected void Page_Load(object sender, EventArgs e)

{

this.countMe();
DataSet tmpDs = new DataSet();
tmpDs.ReadXml(Server.MapPath(“~/counter.xml”));

lblCounter.Text = tmpDs.Tables[0].Rows[0]["hits"].ToString();

}

private void countMe()
{
DataSet tmpDs = new DataSet();
tmpDs.ReadXml(Server.MapPath(“~/counter.xml”));

int hits = Int32.Parse(tmpDs.Tables[0].Rows[0]["hits"].ToString());

hits += 1;

tmpDs.Tables[0].Rows[0]["hits"] = hits.ToString();

tmpDs.WriteXml(Server.MapPath(“~/counter.xml”));
}

.xml page

<?xml version=”1.0″ standalone=”yes”?>
<counter>
<count>
<hits>6</hits>
</count>
</counter>

Advertisement

Entry filed under: asp.net, C#. Tags: , , , .

Getting folder name from drive and Getting file name from folder in C# Find stored procedure

1 Comment Add your own

  • 1. Ali Umair  |  September 19, 2011 at 7:52 am

    Thanks for the solution but the counter is not updating itself.
    might be some problem with the XML file, can you help me?

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

March 2010
M T W T F S S
« Dec   May »
1234567
891011121314
15161718192021
22232425262728
293031  

Follow

Get every new post delivered to your Inbox.