Click here to Skip to main content
15,893,904 members
Articles / Programming Languages / C#

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.9K   218   14  
Visual HTML Meta Tag Generator
using System;
using System.Collections.Generic;
using System.Text;

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;
        }
    }
}

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.

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