Click here to Skip to main content
15,879,184 members
Articles / Programming Languages / C#
Article

HTML Meta Tag Generator

Rate me:
Please Sign up or sign in to vote.
1.82/5 (9 votes)
15 Jan 20071 min read 27.8K   218   14   7
Visual HTML Meta Tag Generator

Sample Image - Meta_Tag_Generator.jpg

Introduction

Because of how often I need to generate Meta Tags for my web pages, and how difficult it is to remember all meta attributes (description, author... etc) I decided to write an application (small one) to do this job for me every time I need (create a new page for my sites).

This set of meta tags is not complete, a meta tag can have many different attributes, but this program i created is only for the ones i use most often(for full list of attributes: ask Google!)

I will generate the tags with only these attributes:
title, description, keywords, author, distribution and revisit

Let's start to create an Object - MetaTagObj to store all the information we need inside.
The code for MetaTagObj class is:

C#
using System;

namespace MetaTagGenerator
{
    class MetaTagObj
    {
        private string title;
        private string desc;
        private string keys;
        private string author;
        private string distribution;
        private string revisit;

        public string Title
        {
            get { return title; }
            set { title = value.Trim(); }
        }
        public string Desc
        {
            get { return desc; }
            set { desc = value.Trim(); }
        }
        public string Keys
        {
            get { return keys; }
            set { keys = value.Trim(); }
        }
        public string Author
        {
            get { return author; }
            set { author = value.Trim(); }
        }
        public string Distribution
        {
            get { return distribution; }
            set 
            {
                if (value.Trim() == "")
                {
                    distribution = "Global";  //default value
                    return;
                }
                distribution = value.Trim(); 
            }
        }
        public string Revisit
        {
            get { return revisit + " Days"; }
            set 
            {
                if (value.Trim() == "")
                {
                    revisit = "10";
                    return;
                }
                revisit = value.Trim();
            }
        }

        public MetaTagObj(): this("Title here", "Description Here", "", "", "", "")
        {
        }
        public MetaTagObj(string title, string desc, string keys, string author, string distribution, string revisit)
        {
            Title = title;
            Desc = desc;
            Keys = keys;
            Author = author;
            Distribution = distribution;
            Revisit = revisit;
        }
        public override string ToString()
        {
            string MetaTag = "";
            MetaTag += "<title>"+ Title + "</title>" + Environment.NewLine;
            MetaTag += "<meta name=\"description\" content=\"" + Desc + "\" />" + Environment.NewLine;
            MetaTag += "<meta name=\"keywords\" content=\"" + Keys + "\" />" + Environment.NewLine;
            MetaTag += "<meta name=\"author\" content=\"" + Author + "\" />" + Environment.NewLine;
            MetaTag += "<meta name=\"distribution\" content=\"" + Distribution + "\" />" + Environment.NewLine;
            MetaTag += "<meta name=\"revisit-after\" content=\"" + Revisit + "\" />" + Environment.NewLine;

            return MetaTag;
        }
    }
}
In this class I do all the work for Meta tag creation (also, I include the TITLE tag here). This class is simple, two constructors, one with parameters, one empty. Some properties for private variables, with some default values (some of them).

The main form contains (screen capture on top of page) few TextBoxes, where the user can introduce data (values for specific attribute.), 3 buttons (Generate, Copy to Clipboard and About) and a TextBox (ReadOnly) for generated code!

. To use this program, you need to fill all the textboxes you want and to press the Generate Button. After this just Copy/Paste the code inside your HTML doc, on HEAD section.

Enjoy!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Engineer
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
raphaelsainfocon12-Jun-09 23:43
raphaelsainfocon12-Jun-09 23:43 
GeneralMy vote of 1 Pin
DanWalker20-May-09 16:31
DanWalker20-May-09 16:31 
GeneralString concatenation Pin
Paulo Morgado16-Jan-07 21:54
professionalPaulo Morgado16-Jan-07 21:54 
AnswerRe: String concatenation Pin
zeltera16-Jan-07 22:23
zeltera16-Jan-07 22:23 
Usually, String.Format or StringBuilder are (recommended to be) used only if you have complex string manipulation.
GeneralRe: String concatenation Pin
Paulo Morgado17-Jan-07 13:22
professionalPaulo Morgado17-Jan-07 13:22 
GeneralRe: String concatenation Pin
zeltera17-Jan-07 23:10
zeltera17-Jan-07 23:10 
GeneralRe: String concatenation Pin
zeltera18-Jan-07 0:04
zeltera18-Jan-07 0:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.