/ Published in: VB.NET
this code shows you how to create a hit counter, you need to create a text file first
Expand |
Embed | Plain Text
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then Dim nCount As Int32 = 0 nCount = GetCounterValue() lblTest.Text = nCount.ToString() End If End Sub Private Function GetCounterValue() As Int32 Dim ctrFile As StreamReader Dim ctrFileW As FileStream Dim sw As StreamWriter Dim strPath As String = Server.MapPath("~/app_data/indexcount.txt") Dim strCounterContents As String Dim nCounter As Int32 strCounterContents = ctrFile.ReadLine().ToString() ctrFile.Close() nCounter = Convert.ToInt32(strCounterContents) Else nCounter = 0 End If nCounter += 1 ctrFileW = New FileStream(strPath, FileMode.OpenOrCreate, FileAccess.Write) sw = New StreamWriter(ctrFileW) sw.WriteLine(Convert.ToString(nCounter)) sw.Close() ctrFileW.Close() Return nCounter End Function
You need to login to post a comment.
