Google sitemap handler/generator for vevocart free

Share on Facebook

Vevocart has a free version which enables a merchant to setup a simple online shop with very little initial capital. However, there are a lot of features on vevocart which are only available with the premium version. One such feature is Search Engine Optimisation or SEO for short.

I needed to provide a dynamically generated google sitemap compatible xml feed for use with the google webmaster tools, so I coded one up in VB.Net. If you need it you may download it by clicking the link below.

using System;
using System.Web;
using System.Xml;
using System.Text;
using System.Configuration;
using System.Data.OleDb;

public class sitemapclass : IHttpHandler
{

public void ProcessRequest(HttpContext context)
   {
    String changefrequency = "weekly"; // always,  hourly,  daily,  weekly,  monthly,  yearly, never
    using (System.IO.TextWriter textWriter=new System.IO.StreamWriter(context.Response.OutputStream,System.Text.Encoding.UTF8))  {
    XmlTextWriter writer = new XmlTextWriter(textWriter);
    writer.Formatting = Formatting.Indented;
    writer.WriteStartDocument();
    writer.WriteStartElement("urlset");
    writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
    
    // Add Domain
    writer.WriteStartElement("url");
    writer.WriteElementString("loc", "http://" + context.Request.ServerVariables["SERVER_NAME"] + context.Request.ApplicationPath.TrimEnd('/'));
    writer.WriteElementString("changefreq",  changefrequency);
    writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
    writer.WriteEndElement();
    // Add Home Page
    writer.WriteStartElement("url");
    writer.WriteElementString("loc", "http://" + context.Request.ServerVariables["SERVER_NAME"] + context.Request.ApplicationPath.TrimEnd('/') + "/Default.aspx");
    writer.WriteElementString("changefreq",  changefrequency);
    writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
    writer.WriteEndElement();
	
	// About Us Page
    writer.WriteStartElement("url");
    writer.WriteElementString("loc", "http://" + context.Request.ServerVariables["SERVER_NAME"] + context.Request.ApplicationPath.TrimEnd('/') + "/AboutUs.aspx");
    writer.WriteElementString("changefreq",  changefrequency);
    writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
    writer.WriteEndElement();
	
	// Contact Us Page
	writer.WriteStartElement("url");
    writer.WriteElementString("loc", "http://" + context.Request.ServerVariables["SERVER_NAME"] + context.Request.ApplicationPath.TrimEnd('/') + "/ContactUs.aspx");
    writer.WriteElementString("changefreq",  changefrequency);
    writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
    writer.WriteEndElement();
	
	// Policy Page
	writer.WriteStartElement("url");
    writer.WriteElementString("loc", "http://" + context.Request.ServerVariables["SERVER_NAME"] + context.Request.ApplicationPath.TrimEnd('/') + "/Policy.aspx");
    writer.WriteElementString("changefreq",  changefrequency);
    writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
    writer.WriteEndElement();

    using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + context.Server.MapPath(ConfigurationManager.ConnectionStrings["MainConnection"].ConnectionString))) 
    {
        using (OleDbCommand productsCommand = new OleDbCommand("SELECT productID, UrlName from Product", conn))
        {
            conn.Open();
            OleDbDataReader productReader = productsCommand.ExecuteReader();
            while (productReader.Read())
            {
			// products
                int productid = int.Parse(productReader["productID"].ToString());
				string urlname = productReader["UrlName"].ToString();
                 writer.WriteStartElement("url");
                 writer.WriteElementString("loc", "http://" + context.Request.ServerVariables["SERVER_NAME"] + context.Request.ApplicationPath.TrimEnd('/') + Vevo.UrlManager.GetProductUrl( productid, urlname ).Replace(@"~",@""));
                 writer.WriteElementString("changefreq", changefrequency);
                 writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
                 writer.WriteEndElement();
            }
        }
				
		using (OleDbCommand categoriesCommand = new OleDbCommand("SELECT CategoryID,UrlName from Category", conn))
        {
            OleDbDataReader categoryReader = categoriesCommand.ExecuteReader();
            while (categoryReader.Read())
            {
			// categories
                int categoryid = int.Parse(categoryReader["CategoryID"].ToString());
				string urlname = categoryReader["UrlName"].ToString();
                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://" + context.Request.ServerVariables["SERVER_NAME"] + context.Request.ApplicationPath.TrimEnd('/') + Vevo.UrlManager.GetCategoryUrl( categoryid, urlname ).Replace(@"~",@""));
                writer.WriteElementString("changefreq", changefrequency);
                writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
                writer.WriteEndElement();
            }
        }			
    }
    writer.WriteEndDocument();
    }
}

public bool IsReusable
{
    get
    {
        return false;
    }
}

}

 

Please post any bugs or feedbacks. As usual the download is without any warranty what so ever.

HTH

 

sitemap.ashx (5.37 kb)

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListkick it on DotNetKicks.comTwitThis

Comments are closed

About Me

When not scratching my head for solutions to software challenges, I spend my time playing with my little boy - Michael Jnr.

Quotations

"Anger is never without Reason, but seldom with a good One."
Benjamin Franklin

Donate with PayPal - it

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2005 - 2010

Search