A Plethora of Cockamamie Asp.Net Clap Trap

The Forgotton Code

I am creating this article because whenever I start a new project from scratch, I always forget about the small things that we all do to get started. If you have an idea of more stuff to put here, send me an email and I will post them. So here is a list of all those usefull resources that get forgotten about until you start a new project.

Code List

C# IsNumeric

    public static bool IsNumeric(string strInput)
    {
        Int32 i = strInput.Length;
        Int32 x;

        for (x = 0; x < i; x++)
        {
            if (!(char.IsNumber(strInput, x)))
            {
                return false;
            }
        }
        return true;
    }

US States XML

<?xml version="1.0" encoding="utf-8" ?>
<states>
  <!--US States and Territories-->
  <state>
    <name>Alabama</name>
    <abbrv>AL</abbrv>
    <id></id>
  </state>
  <state>
    <name>Alaska</name>
    <abbrv>AK</abbrv>
    <id></id>
  </state>
  <state>
    <name>Arkansas</name>
    <abbrv>AR</abbrv>
    <id></id>
  </state>
  <state>
    <name>Arizona</name>
    <abbrv>AZ</abbrv>
    <id></id>
  </state>
  <state>
    <name>California</name>
    <abbrv>CA</abbrv>
    <id></id>
  </state>
  <state>
    <name>Colorado</name>
    <abbrv>CO</abbrv>
    <id></id>
  </state>
  <state>
    <name>Connecticut</name>
    <abbrv>CT</abbrv>
    <id></id>
  </state>
  <state>
    <name>District of Columbia</name>
    <abbrv>DC</abbrv>
    <id></id>
  </state>
  <state>
    <name>Delaware</name>
    <abbrv>DE</abbrv>
    <id></id>
  </state>
  <state>
    <name>Florida</name>
    <abbrv>FL</abbrv>
    <id></id>
  </state>
  <state>
    <name>Georgia</name>
    <abbrv>GA</abbrv>
    <id></id>
  </state>
  <state>
    <name>Hawaii</name>
    <abbrv>HI</abbrv>
    <id></id>
  </state>
  <state>
    <name>Idaho</name>
    <abbrv>ID</abbrv>
    <id></id>
  </state>
  <state>
    <name>Illinois</name>
    <abbrv>IL</abbrv>
    <id></id>
  </state>
  <state>
    <name>Indiana</name>
    <abbrv>IN</abbrv>
    <id></id>
  </state>
  <state>
    <name>Iowa</name>
    <abbrv>IA</abbrv>
    <id></id>
  </state>
  <state>
    <name>Kansas</name>
    <abbrv>KS</abbrv>
    <id></id>
  </state>
  <state>
    <name>Kentucky</name>
    <abbrv>KY</abbrv>
    <id></id>
  </state>
  <state>
    <name>Louisiana</name>
    <abbrv>LA</abbrv>
    <id></id>
  </state>
  <state>
    <name>Maine</name>
    <abbrv>ME</abbrv>
    <id></id>
  </state>
  <state>
    <name>Maryland</name>
    <abbrv>MD</abbrv>
    <id></id>
  </state>
  <state>
    <name>Massachusetts</name>
    <abbrv>MA</abbrv>
    <id></id>
  </state>
  <state>
    <name>Michigan</name>
    <abbrv>MI</abbrv>
    <id></id>
  </state>
  <state>
    <name>Minnesota</name>
    <abbrv>MN</abbrv>
    <id></id>
  </state>
  <state>
    <name>Mississippi</name>
    <abbrv>MS</abbrv>
    <id></id>
  </state>
  <state>
    <name>Missouri</name>
    <abbrv>MO</abbrv>
    <id></id>
  </state>
  <state>
    <name>Montana</name>
    <abbrv>MT</abbrv>
    <id></id>
  </state>
  <state>
    <name>Nebraska</name>
    <abbrv>NE</abbrv>
    <id></id>
  </state>
  <state>
    <name>Nevada</name>
    <abbrv>NV</abbrv>
    <id></id>
  </state>
  <state>
    <name>New Hampshire</name>
    <abbrv>NH</abbrv>
    <id></id>
  </state>
  <state>
    <name>New Jersey</name>
    <abbrv>NJ</abbrv>
    <id></id>
  </state>
  <state>
    <name>New Mexico</name>
    <abbrv>NM</abbrv>
    <id></id>
  </state>
  <state>
    <name>New York</name>
    <abbrv>NY</abbrv>
    <id></id>
  </state>
  <state>
    <name>North Carolina</name>
    <abbrv>NC</abbrv>
    <id></id>
  </state>
  <state>
    <name>North Dakota</name>
    <abbrv>ND</abbrv>
    <id></id>
  </state>
  <state>
    <name>Ohio</name>
    <abbrv>OH</abbrv>
    <id></id>
  </state>
  <state>
    <name>Oklahoma</name>
    <abbrv>OK</abbrv>
    <id></id>
  </state>
  <state>
    <name>Oregon</name>
    <abbrv>OR</abbrv>
    <id></id>
  </state>
  <state>
    <name>Pennsylvania</name>
    <abbrv>PA</abbrv>
    <id></id>
  </state>
  <state>
    <name>Rhode Island</name>
    <abbrv>RI</abbrv>
    <id></id>
  </state>
  <state>
    <name>South Carolina</name>
    <abbrv>SC</abbrv>
    <id></id>
  </state>
  <state>
    <name>South Dakota</name>
    <abbrv>SD</abbrv>
    <id></id>
  </state>
  <state>
    <name>Tennessee</name>
    <abbrv>TN</abbrv>
    <id></id>
  </state>
  <state>
    <name>Texas</name>
    <abbrv>TX</abbrv>
    <id></id>
  </state>
  <state>
    <name>Utah</name>
    <abbrv>UT</abbrv>
    <id></id>
  </state>
  <state>
    <name>Vermont</name>
    <abbrv>VT</abbrv>
    <id></id>
  </state>
  <state>
    <name>Virginia</name>
    <abbrv>VA</abbrv>
    <id></id>
  </state>
  <state>
    <name>Washington</name>
    <abbrv>WA</abbrv>
    <id></id>
  </state>
  <state>
    <name>West Virginia</name>
    <abbrv>WV</abbrv>
    <id></id>
  </state>
  <state>
    <name>Wisconsin</name>
    <abbrv>WI</abbrv>
    <id></id>
  </state>
  <state>
    <name>Wyoming</name>
    <abbrv>WY</abbrv>
    <id></id>
  </state>
</states>

US States Class

using System;

public class USState
{
    private String _name;
    /// <summary>
    /// Property Name (System.String)
    /// </summary>
    public String Name
    {
        get { return this._name; }
        set { this._name = value; }
    }

    private String _abbreviation;
    /// <summary>
    /// Property Abbreviation (System.String)
    /// </summary>
    public String Abbreviation
    {
        get { return this._abbreviation; }
        set { this._abbreviation = value; }
    }
}

US States Cache Code

using System;
using System.Xml;
using System.Collections.Generic;

/// <summary>
/// Manages Site cache and Lists
/// </summary>
public class SiteGenList
{
    public static List<USState> GetUSStates()
    {
        System.Web.HttpContext ctx = System.Web.HttpContext.Current;
        ctx.Trace.Write("SiteGenList.GetUSStates()", "Started");

        List<USState> l = new List<USState>();

        if (ctx.Cache["USStates"] == null)
        {
            XmlTextReader xtr = new XmlTextReader(ctx.Server.MapPath("/_xmldata/usstates.xml"));
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(xtr);
            XmlNodeList nl = xDoc.SelectNodes("/states/state");
            USState us;
            for (Int32 i = 0; i < nl.Count; i++)
            {
                us = new USState();
                us.Name = nl[i]["name"].InnerText.Trim();
                us.Abbreviation = nl[i]["abbrv"].InnerText.Trim();
                l.Add(us);
            }

            l.Sort(delegate (USState us1, USState us2)
            {
                return us1.Name.CompareTo(us2.Name);
            });

            ctx.Cache.Insert("USStates", l, null, DateTime.Now.AddDays(30), TimeSpan.Zero);
            ctx.Trace.Warn("SiteGenList.GetUSStates()", "Returning From File Read");
        }
        else
        {
            l = (List<USState>)ctx.Cache["USStates"];
            ctx.Trace.Write("SiteGenList.GetUSStates()", "Returning From Cache");
        }
        return l;
    }
}

US States Dropdownlist

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            List<USState> l = SiteGenList.GetUSStates();
            Trace.Warn("Building Statelist", "Started");
            ddlStates.Items.Add(new ListItem("Select", "XX"));
            for (Int32 i = 0; i < l.Count; i++)
            {
                ddlStates.Items.Add(new ListItem(l[i].Name, l[i].Abbreviation));
            }
            Trace.Warn("Building Statelist", "Ended");
        }
    }