Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Easy Desktop Web Stats

, 23 Oct 2012 CPOL
Create a Windows desktop app to display daily web stats from your personal site
using System;
using System.IO;
using System.Xml;
using System.Net;
using System.Windows.Forms;
using System.Media;

namespace Desktop_Web_Stats
    public partial class Main  
        // change this to the URL of your site
        private string statsURL = "";

        private Timer dataRequestTimer = new Timer();
        private SoundPlayer ding = new SoundPlayer(Properties.Resources.Ding);        

        private DataGridViewCell messageCell;
        private DataGridViewCell tooltipCell;       
        private void CreateDataRequestCycle()
            dataRequestTimer.Tick += new EventHandler(dataRequestTimer_Tick);            
            statsGrid.CellClick += new DataGridViewCellEventHandler(statsGrid_CellClick);

            // initial delay of 8 seconds to allow Windows to finish loading other startup programs and to start the network connection;

            messageCell = statsGrid.Rows[0].Cells[0];
            messageCell.Value = "Wait...";

            tooltipCell = statsGrid.Rows[0].Cells[3];           

        private void InitDataRequestCycle(int nInterval)
            dataRequestTimer.Interval = nInterval;
        private void dataRequestTimer_Tick(object sender, EventArgs e)

            WebRequest statsRequest = null;              
            StreamReader statsStream;

                string lastHitTimeString = (string)statsGrid.Rows[0].Cells[3].Value;

                statsRequest = WebRequest.Create(statsURL); 
                WebResponse statsResponse = statsRequest.GetResponse();
                statsStream = new StreamReader(statsResponse.GetResponseStream());
                XmlDocument statsXMLDocument = new XmlDocument();
                XmlNode stats = statsXMLDocument.SelectSingleNode("Stats");

                short n = 0;
                foreach (XmlNode stat in stats)
                    statsGrid.Rows[0].Cells[n++].Value = stat.InnerText;
                tooltipCell.ToolTipText = "Last request: " + DateTime.Now.ToShortTimeString();
                if ((string)statsGrid.Rows[0].Cells[3].Value != lastHitTimeString && settings.playDing)

                messageCell.Value = "Retry";
                messageCell.Selected = true;               

            messageCell.Selected = false;
            InitDataRequestCycle(settings.updateInterval * 1000 * 60); 

        private void statsGrid_CellClick(object sender, DataGridViewCellEventArgs e)
            statsGrid.CurrentCell.Selected = false;           

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Michael J Hill - OH

United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150129.1 | Last Updated 23 Oct 2012
Article Copyright 2012 by Michael J Hill - OH
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid