Technorati Tagger

I’ve been trying to keep up with my tags and such with Technorati, but have fallen behind. It is a little cumbersome to add the HTML code for these tags for each post. I finally decided to do something about it.

This is a really small program. Really small. Really Simple. I type in a list of keywords and hit a button to generate the HTML code for me. This copies the links into my clipboard and then I just paste them into the application (or web browser) that I’m using to create and edit posts.

Download: TechnoratiTagger.zip

Troubleshooting
The file should work as-is for Microsoft Windows XP. If you haven’t downloaded the Microsoft .Net Framework 1.1 from windows update, then you may run into some problems running this program. Simple go to windows update and download the latest framework.

If you are running the file from a mapped network drive, or from a shared directory on another computer, you may also run into problems. Just copy the file to your local hard drive and run it from there.

Code
The code is written on the Microsoft .Net platform in C# and is free for anyone to use.

    1 using System;
    2 using System.Drawing;
    3 using System.Collections;
    4 using System.ComponentModel;
    5 using System.Windows.Forms;
    6 using System.Data;
    7 using System.Web;
    8 using System.IO;
    9 using System.Text;
   10 
   11 namespace TechnoratiTagger
   12 {
   13     public class Form1 : System.Windows.Forms.Form
   14     {
   15         private System.Windows.Forms.Label lblTags;
   16         private System.Windows.Forms.TextBox txtTags;
   17         private System.Windows.Forms.Button btnCopy;
   18         private System.ComponentModel.Container components = null;
   19         public Form1()
   20         {
   21             InitializeComponent();
   22         }
   23         protected override void Dispose( bool disposing )
   24         {
   25             if( disposing )
   26             {
   27                 if (components != null)
   28                 {
   29                     components.Dispose();
   30                 }
   31             }
   32             base.Dispose( disposing );
   33         }
   34 
   35         #region Windows Form Designer generated code
   36         /// <summary>
   37         /// Required method for Designer support - do not modify
   38         /// the contents of this method with the code editor.
   39         /// </summary>
   40         private void InitializeComponent()
   41         {
   42             this.lblTags = new System.Windows.Forms.Label();
   43             this.txtTags = new System.Windows.Forms.TextBox();
   44             this.btnCopy = new System.Windows.Forms.Button();
   45             this.SuspendLayout();
   46             //
   47             // lblTags
   48             //
   49             this.lblTags.AutoSize = true;
   50             this.lblTags.Location = new System.Drawing.Point(10, 10);
   51             this.lblTags.Name = “lblTags”;
   52             this.lblTags.Size = new System.Drawing.Size(139, 16);
   53             this.lblTags.TabIndex = 0;
   54             this.lblTags.Text = “Tags (seperate by comma)”;
   55             //
   56             // txtTags
   57             //
   58             this.txtTags.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
   59                 | System.Windows.Forms.AnchorStyles.Left)
   60                 | System.Windows.Forms.AnchorStyles.Right)));
   61             this.txtTags.Location = new System.Drawing.Point(10, 30);
   62             this.txtTags.Multiline = true;
   63             this.txtTags.Name = “txtTags”;
   64             this.txtTags.Size = new System.Drawing.Size(260, 80);
   65             this.txtTags.TabIndex = 1;
   66             this.txtTags.Text = “”;
   67             //
   68             // btnCopy
   69             //
   70             this.btnCopy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
   71             this.btnCopy.Location = new System.Drawing.Point(180, 120);
   72             this.btnCopy.Name = “btnCopy”;
   73             this.btnCopy.Size = new System.Drawing.Size(90, 23);
   74             this.btnCopy.TabIndex = 2;
   75             this.btnCopy.Text = “Copy as HTML”;
   76             this.btnCopy.Click += new System.EventHandler(this.btnCopy_Click);
   77             //
   78             // Form1
   79             //
   80             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   81             this.ClientSize = new System.Drawing.Size(282, 156);
   82             this.Controls.Add(this.btnCopy);
   83             this.Controls.Add(this.txtTags);
   84             this.Controls.Add(this.lblTags);
   85             this.Name = “Form1″;
   86             this.Text = “Technorati Tagger”;
   87             this.Load += new System.EventHandler(this.Form1_Load);
   88             this.Closed += new System.EventHandler(this.Form1_Closed);
   89             this.ResumeLayout(false);
   90 
   91         }
   92         #endregion
   93 
   94         [STAThread]
   95         static void Main()
   96         {
   97             Application.Run(new Form1());
   98         }
   99         private void btnCopy_Click(object sender, System.EventArgs e)
  100         {
  101             string[] tags = txtTags.Text.Split(new char[]{‘,’});
  102             const string link = @”<a href=”"http://technorati.com/tags/{0}”" rel=”"tag”">{1}</a>”;
  103             const string template = @”<span class=”"Tags”">Tags: {0}</span>”;
  104             StringBuilder sb = new StringBuilder();
  105             for(int i = 0; i < tags.Length; i++)
  106             {
  107                 string tag = tags[i].Trim();
  108                 if(tag == string.Empty) continue;
  109                 if(sb.Length != 0) sb.Append(“, “);
  110                 sb.AppendFormat(link,
  111                     HttpUtility.HtmlEncode(HttpUtility.UrlEncode(tag)),
  112                     HttpUtility.HtmlEncode(tag));
  113             }
  114             if(sb.Length == 0)
  115             {
  116                 MessageBox.Show(this, “No tags to copy”);
  117                 return;
  118             }
  119             Clipboard.SetDataObject(string.Format(template, sb.ToString()), true);
  120         }
  121 
  122         private void Form1_Closed(object sender, System.EventArgs e)
  123         {
  124             WriteText(“tags.txt”, txtTags.Text);
  125         }
  126         private void Form1_Load(object sender, System.EventArgs e)
  127         {
  128             txtTags.Text = ReadText(“tags.txt”);
  129             txtTags.SelectionStart = txtTags.Text.Length;
  130         }
  131         private string ReadText(string name)
  132         {
  133             string fileName = FilePath(name);
  134             if(!File.Exists(fileName)) return string.Empty;
  135             StreamReader reader = null;
  136             try
  137             {
  138                 reader = File.OpenText(fileName);
  139                 return reader.ReadToEnd();
  140             }
  141             finally
  142             {
  143                 if(reader != null) reader.Close();
  144             }
  145         }
  146         private void WriteText(string name, string text)
  147         {
  148             string fileName = FilePath(name);
  149             StreamWriter writer = null;
  150             try
  151             {
  152                 writer = File.CreateText(fileName);
  153                 writer.Write(text);
  154             }
  155             finally
  156             {
  157                 if(writer != null) writer.Close();
  158             }
  159         }
  160         private string FilePath(string name)
  161         {
  162             return Path.GetDirectoryName(Application.ExecutablePath) + “\\” + name;
  163         }
  164     }
  165 }

Tags: , , , , , , , , , ,

8 Responses to “Technorati Tagger”

  1. thomas Says:

    Cool App!

  2. russell Says:

    So how do I use this code?

  3. Lewis Moten Says:

    Ok, I posted a zip file that you can use.

    http://www.klooze.com/TechnoratiTagger.zip

  4. Jonas M Luster Says:

    Whow, this is freaking cool. Linked :)

  5. russell Says:

    Thanks again.

  6. Jay4DaTaste Says:

    Lewis,

    This program is just what I have been looking for, I have been doing some research on the Technocrati Tags in the last month or so, but like you said, it’s a lot of work to do it. I have about 400 or so posts so far, but now with your program, I think I will actually do something about tagging them. I’m going to download it, and try it out!

    Keep up the good work Lewis!

    Jay

  7. ~Angel Says:

    U are now my hero!! What a great tool! It’s so cumbersome getting the tags and this will save me a ton of time.

  8. Taoski Says:

    I wish there was a web version of this!

Leave a Reply