View Counter in asp.net ?

Posted by prashant12-7256 under ASP.NET on 10/29/2010 | Points: 10 | Views : 2579 | Status : [Member] | Replies : 2
View Counter in asp.net ?
Like in youTube Website

View Counter to count number of view of an article / Content from database ?




Responses

Posted by: Raja on: 10/29/2010 [Member] Starter | Points: 25

Up
0
Down
Keep a column in the database table of type int, say ViewCount. When the record is being accessed, write the select command to access the record and after that update the ViewCount column

Something like
update tablename set ViewCount = ViewCount + 1 where recordid -5


Hope this will help you.

Thanks

Regards,
Raja, USA

prashant12-7256, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lalji_mer on: 10/29/2010 [Member] Bronze | Points: 25

Up
0
Down
Simple way you can do this using .txt file create text file myappcounter.txt and put in to your website folder first set 0(Zero)in txt file and give permition in IIS for Read and wright.

private int GetCounterValue()
{
StreamReader ctrFile;
FileStream ctrFileW;
StreamWriter sw;

string strPath = Server.MapPath( "myappcounter.txt");
string strCounterContents;
int nCounter;
if (File.Exists(strPath))
{
ctrFile = File.OpenText(strPath);
strCounterContents = ctrFile.ReadLine().ToString();
ctrFile.Close();
nCounter = Convert.ToInt32(strCounterContents);
}
else
nCounter = 0;

nCounter++;

ctrFileW = new FileStream(strPath, FileMode.OpenOrCreate,FileAccess.Write);
sw = new StreamWriter(ctrFileW);
sw.WriteLine(Convert.ToString(nCounter));
sw.Close();
ctrFileW.Close();

return nCounter;
}

Another reference code you will get here
http://www.aspnettutorials.com/tutorials/database/hit-cntr-asp4-cs.aspx
http://www.dotnetspider.com/resources/35163-Hit-Counter-C.aspx
http://www.freevbcode.com/ShowCode.asp?ID=2276

LP MER

prashant12-7256, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response