HTML to PDF

Have you ever wanted a function to convert HTML to PDF? It is really easy. A good use of this is when you have a resume on your website and you want to create a download of it as a PDF. Mind you; you will have to properly format your resume so it looks good in both cases. Not the easiest job, but totally worth while to have a resume download created on demand. Continue reading HTML to PDF

Starting a WebForm Project

    I started working in the DotNet while it was in the Beta stage. Ewe Beta! Since then I discovered there is more than one way to tackle a start of a project and I have perfected it for my purpose.

    I would suggest starting with an empty project rather than letting Microsoft build you one. By you creating an empty project you are able to control what goes in it. The “Web Forms”template that Microsoft offers has so many files and structure that you would likely not even use.
    Continue reading Starting a WebForm Project

Auto-Link Using Regular Expressions

Auto-LinkingI was recently asked if I could automatically turn website text (ex: www.google.com ) into HTML hyperlinks.  My first thought was ah CRAP!  I also wondered why they could not use the link tool in the editor, but they asked so I delivered. With about 5 minutes on Google, I found the perfect solution that worked for me.

Mind you I was working in C# for this, but since it is a regular expression solution; it will apply to virtually any language.  The one change that I had made from the original code was to add in a piece that also auto-linked when the text included “http://www.”.  You may or may not want the extra addition that I had made.

Continue reading Auto-Link Using Regular Expressions

Building a C-Sharp Class

I have created this example of a C# class to demonstrate one way of creating a basic class cbject representing one employee.  This class could be used as a starting point for just about any object.

Take note that there are no business rules in this example.  It is of my opinion that you create a basic object first and create a business class second which extends the basic object.  In the business class you may put an EmployeeNumber generator, MaxLength controls on the fields, Phone number validation and other rules that may apply based on your business practices.  A business class will be demonstrated in a later blog.

You may also want to create a collection class.  A collection class or a manager class would manage a collection of objects with Add, Remove, Select, Sort type functions.  This too will be demonstrated in a later blog.

    /// <summary>
    /// Class Object Representing Employee
    /// </summary>
    public class Employee : Dictionary<String, Object>, IEmployee
    {
        // ***********************| Properties |***********************
        /// <summary>
        /// Employee Number
        /// </summary>
        public String EmployeeNumber
        {
            get { return (String)this[GetName()]; }
            set { this[GetName()] = value; }
        }

        /// <summary>
        /// Employee's First Name
        /// </summary>
        public String FirstName
        {
            get { return (String)this[GetName()]; }
            set { this[GetName()] = value; }
        }

        /// <summary>
        /// Employee's Last Name
        /// </summary>
        public String LastName
        {
            get { return (String)this[GetName()]; }
            set { this[GetName()] = value; }
        }
        /// <summary>
        /// Employee's Address Line 1
        /// </summary>
        public String Address1
        {
            get { return (String)this[GetName()]; }
            set { this[GetName()] = value; }
        }

        /// <summary>
        /// Employee's Address Line 2
        /// </summary>
        public String Address2
        {
            get { return (String)this[GetName()]; }
            set { this[GetName()] = value; }
        }

        /// <summary>
        /// Employee's City
        /// </summary>
        public String City
        {
            get { return (String)this[GetName()]; }
            set { this[GetName()] = value; }
        }

        /// <summary>
        /// Employee's Province / State
        /// </summary>
        public String Province
        {
            get { return (String)this[GetName()]; }
            set { this[GetName()] = value; }
        }

        /// <summary>
        /// Employee's Country
        /// </summary>
        public String Country
        {
            get { return (String)this[GetName()]; }
            set { this[GetName()] = value; }
        }

        /// <summary>
        /// Employee's ZIP / Postal Code
        /// </summary>
        public String ZipPostal
        {
            get { return (String)this[GetName()]; }
            set { this[GetName()] = value; }
        }

        /// <summary>
        /// Employee's Home Phone Number
        /// </summary>
        public String HomePhoneNumber
        {
            get { return (String)this[GetName()]; }
            set { this[GetName()] = value; }
        }

        /// <summary>
        /// Employee's Cell Phone Number
        /// </summary>
        public String CellPhoneNumber
        {
            get { return (String)this[GetName()]; }
            set { this[GetName()] = value; }
        }

        /// <summary>
        /// Employee's Full Name ( ReadOnly )
        /// </summary>
        public String FullName
        {
            get { return String.Format("{0}, {1}", FirstName, LastName); }
        }

        /// <summary>
        /// Employee's Start Date
        /// </summary>
        public DateTime StartDate
        {
            get { return (DateTime)this[GetName()]; }
            set { this[GetName()] = value; }
        }

        /// <summary>
        /// Employee's TerminationDate ( Nullable )
        /// </summary>
        public DateTime? TerminationDate
        {
            get { return (DateTime?)this[GetName()]; }
            set { this[GetName()] = value; }
        }
        // ***********************| Constructor(s) |***********************
        /// <summary>
        /// Constructor
        /// </summary>
        public Employee()
        {
            Initialize();
        }

        /// <summary>
        /// Employee
        /// </summary>
        /// <param name="employeeNumber">Initial Employee Number</param>
        public Employee(String employeeNumber)
        {
            Initialize();
            EmployeeNumber = employeeNumber;
        }
        // ***********************| Methods |***********************

        /// <summary>
        /// Initialize the Class
        /// </summary>
        private void Initialize()
        {
            EmployeeNumber = "";
            FirstName = "";
            LastName = "";
            Address1 = "";
            Address2 = "";
            City = "";
            Province = "";
            Country = "";
            ZipPostal = "";
            HomePhoneNumber = "";
            CellPhoneNumber = "";
        }

        /// <summary>
        /// Get Method Name
        /// </summary>
        /// <returns>First and Last Name</returns>
        public String GetName()
        {
            StackTrace stackTrace = new StackTrace();
            StackFrame stackFrame = stackTrace.GetFrame(1);
            MethodBase methodBase = stackFrame.GetMethod();
            return methodBase.Name.Replace("set_", "").Replace("get_", "");
        }

        /// <summary>
        /// Re-initializes the Class
        /// </summary>
        public void Reset()
        {
            this.Clear();
            Initialize();
        }
    }

Posting Data From HTML to ASPX

Recently I had a need to have a web site post credentials to another web site.   The first site was standard HTML and the second site was DotNet (ASP.NET).

In this example, we will be passing a user name and password to another site.

Sending Web Site
In your sending website, you will need a log in  panel similar to the one below.

    






Receiving Web Site
In the form load of your DotNet (ASP.NET) site, you will need the following code to get the values from the request object and then pass to your log in routine.

                NameValueCollection nvc = Request.Form;
string userName = "";
string password = "";
if (!string.IsNullOrEmpty(nvc["txtUserName"]))
{
userName = nvc["txtUserName"];
}

if (!string.IsNullOrEmpty(nvc["txtPassword"]))
{
password = nvc["txtPassword"];
}

ExecuteLogin(userName, password);