Hello,
I have attempted to write a simple hit counter using both *.txt files and *.xml files.
The hit counters seem to work locally, however, when I upload these files to my production server, the code does not seem to recognize the *.txt files or the *.xml files.
My code for the *.txt files follow:
-------------------
<form id="form1" runat="server">
<div>
<table border="1">
<tr>
<td> Visitor Count: </td>
<td valign="top" align="center" style="background-color:Aqua;" >
<asp:Label ID="Label1" runat="server" Text="Visitor Count:"></asp:Label>
</td>
</tr>
</table>
</div>
</form>
----------------
My codebehind follows:
---------------
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
namespace HSCO_Sheriff_ExternalWeb
{
public partial class WebForm15 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Application.Lock();
//Response.Write(gethitcounts());
Label1.Text = gethitcounts();
Application.UnLock();
}
public string gethitcounts()
{
string lastcount = "";
try
{
StreamReader SR = File.OpenText(System.Web.HttpContext.Current.Server.MapPath("counter/hitcounter_webform15.txt"));
string getcount = null;
while ((getcount = SR.ReadLine()) != null)
{
lastcount = lastcount + getcount;
}
SR.Close();
long newcount = Convert.ToInt64(lastcount);
newcount++;
TextWriter TxtWtr = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath("counter/hitcounter_webform15.txt"));
TxtWtr.WriteLine(Convert.ToString(newcount));
TxtWtr.Close();
SR = File.OpenText(System.Web.HttpContext.Current.Server.MapPath("counter/hitcounter_webform15.txt"));
getcount = null;
lastcount = "";
while ((getcount = SR.ReadLine()) != null)
{
lastcount = lastcount + getcount;
}
SR.Close();
}
catch (Exception ex)
{
TextWriter TxtWtr = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath("counter/hitcounter_webform15.txt"));
TxtWtr.WriteLine(Convert.ToString("1"));
TxtWtr.Close();
lastcount = "1";
}
return lastcount;
}
}
}
--------------
Any help in getting this to work OR any code examples that function to provide a simple page count would be greatly appreciated.