troubleshooting Question

asp.net C# hit counter

Avatar of Codeaddict7423
Codeaddict7423Flag for United States of America asked on
XMLASP.NET
7 Comments1 Solution2331 ViewsLast Modified:
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.
ASKER CERTIFIED SOLUTION
darjimaulik

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros