C# Template for Creating Google Video Sitemap

December 31, 2007 | Uncategorized | 7 Comments

Earlier this month, Google introduced “Video Sitemaps” as an extension to the Sitemap Protocol standard. It allows website owners to expose their video content (including embedded video) to be indexed and included in Google’s video search (here is Google’s spec). Embrace and extend 😉

I just added this to Dallas Theological Seminary‘s site: http://www.dts.edu/videositemap.xml and I thought it might help to share the template to speed someone else’s development:

using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Xml;
using System.Text;

namespace YourNamespace
    public class VideoSiteMap : IHttpHandler
        public VideoSiteMap()
        public void ProcessRequest(HttpContext context)
            XmlTextWriter writer = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8); 
            context.Response.ContentType = "text/xml";

            writer.Formatting = Formatting.Indented;
            // add namespaces
            writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
            writer.WriteAttributeString("xmlns", "video", null, "http://www.google.com/schemas/sitemap-video/1.0");
            // fake loop
            for (int i=0; i<10; i++) {

				// required
                writer.WriteElementString("loc", "http://mysite.com/myplayer.aspx");
                writer.WriteStartElement("video", "video", null); 
                // start:optional
                writer.WriteElementString("video", "title", null, "Video Title");
                writer.WriteElementString("video", "description", null, "a great video");
                writer.WriteElementString("video", "thumbnail_loc", null, "http://mysite.com/myvideothumb.jpg");
                writer.WriteElementString("video", "family_friendly", null, "Yes");
                writer.WriteElementString("video", "content_loc", null, "http://mysite.com/myvideo.flv");
                writer.WriteElementString("video", "duration", null, "100");                    
                writer.WriteStartElement("video", "player_loc", null);                
                writer.WriteAttributeString("allow_embed", "true");
                writer.WriteEndElement(); // video:player_loc
                // end:optional
                writer.WriteEndElement(); // video:video
                writer.WriteEndElement(); //url
            writer.WriteEndElement(); //urlset 
        public bool IsReusable
            get { return false; }

Just add this class to your web.config and you’re all set:

      <add verb="*" path="videositemap.xml" type="YourNamespace.VideoSiteMap, YourNamespace"/>

Hope that helps!

7 responses to “C# Template for Creating Google Video Sitemap”

  1. I assume you had to compile this and stick it in the bin folder. Did you also have to make any adjustments in IIS for this to work? Once I added the add tag to my web.config file, I’ve just gotten an error on my dev site where I’m testing this out: http://dev.greenenergytv.com

    Thanks for the code; looking forward to hooking this up.

  2. You are welcome to invite me on chat at the MSN and Yahoo id’s for further discussions, clarifications and testing of our services.
    MSN id: sonali.rasal@routesms.com

    Yahoo id :sonalir_routesms@yahoo.com

    Skype id: sonalir_routesms


  3. trif3cta says:

    Thanks for posting this, I’ve been on the hunt for something similar.

  4. İLYAS says:

    thank you very muck thanks

  5. Voila un site super bien de films et scenes manga et en streaming
    et telechargement legal gratuit et toute suggestion ou demande d’ajout d’un film sera la bienvenue.
    Et decouvrez ce que les films que vous cherchez.

    Review my page http://Tcbusinessmobile.Wpquicksites.Com

  6. Duct cleaning should only be performed on an as-needed basis; anything more frequent is not cost-effective.

    The service offers thorough cleaning and maintenance
    of the heat regulatory and temperature modulation systems.

    – Light use of 2-6 hours per day requires cleaning every
    12 months.

  7. Awesome and an highly interesting post to stumble at on this massive website! Never write some replies only now i couldnt i could not resist ..

Hi, I'm John Dyer. In my day job, I build websites and create online seminary software for a seminary in Dallas. I also like to release open source tools including a pretty popular HTML5 video player and build tools that help people find best bible commentaries and do bible study. And just for fun, I also wrote a book on the theology of technology and media.

Fork me on GitHub

Social Widgets powered by AB-WebLog.com.