How To Create a Windows Live Writer Twitter Plugin That Supports bit.ly

Don’t get me wrong; I love the Twitter Notify plugin that you can download for Live Writer (which is itself the most amazing piece of software in existence today). However, I track almost all of my stuff through a bit.ly account and I tweet about every blog post. I want the option to use bit.ly instead of tinyurl. So, a new plugin must be created!

Looking for more tips on Writer plugin development? Check out the Top Tips for Writer Plug-in Developers at Scott Lovegrove’s blog.

Creating the solution

Right now, Writer supports plugins that run on the .NET Framework 1.1 or 2.0. You can still use VS2010, just target the project to the 2.0 framework to ensure that it will compile.

Before we start, make sure that you have Windows Live Writer installed. The API is installed by default in the C:\Program Files\Windows Live\Writer.

Let’s go ahead and get started!

  1. Start by creating a new Class Library project. Make sure to target the project to .NET Framework 2.0.
    image

  2. Add a reference to the Windows Live Writer API using Browse on the Add Reference dialog. I’m on a 64-bit machine so this file is located at: 
    C:\Program Files (x86)\Windows Live\Writer\WindowsLive.Writer.Api.dll

  3. Add a reference to the .NET 2.0 System.Windows.Forms library.

  4. Rename your Class1.cs file to MyBitlyTweeterPlugin.cs

  5. Open MyBitlyTweeterPlugin.cs and add a using directive for System.Windows.Forms and WindowsLive.Writer.Api. This gives you access to the Writer API.

     using System.Windows.Forms;
    using WindowsLive.Writer.Api;
    
  6. Your main class should derive from the PublishNotificationHook base class. This gives your class the ability to execute just before or just after a post is published. Here’s the documentation for that class. Since we only want to tweet about something after the post has been published, we’ll override the OnPostPublish method of the base class. Here’s the code so far:

        1: using System;
        2: using System.Collections.Generic;
        3: using System.Text;
        4: using System.Windows.Forms;
        5: using WindowsLive.Writer.Api;
        6:  
        7: namespace MyBitlyTweeter
        8: {
        9:     public class MyBitlyTweeterPlugin : PublishNotificationHook
       10:     {
       11:         public override void OnPostPublish(IWin32Window dialogOwner, IProperties properties, IPublishingContext publishingContext, bool publish)
       12:         {
       13:             base.OnPostPublish(dialogOwner, properties, publishingContext, publish);
       14:         } 
       15:     }
       16: }
    
  7. Use the GUID Generator tool (you can find it by typing in GUID Generator in Windows Search) to generate a new GUID. You’ll need it to identify the plugin.

    image

  8. Adorn your class with the WriterPluginAttribute attribute using the GUID you generated.

     [WriterPlugin("CD0182F3-54DC-42FA-8330-469CA1E7EE58", "bit.ly + twitter plugin", Description="Allows you to send a tweet with a bit.ly url tied to your account.", PublisherUrl="https://www.danwaters.com")]
     public class MyBitlyTweeterPlugin : PublishNotificationHook
      ...
    

Comments

  • Anonymous
    December 30, 2010
    Hey, thanks for the plug-in— saw it in the new Windows Live Writer gallery.. You have like 7 download's. Here's a link to the main Windows Live Writer gallery... for others     http://plugins.live.com/writer I downloaded it and found it great.     lehsys.blogspot.com/.../windows-live-writer-bitly-tweeter.html And while I find these plug-ins awesome; someone needs to start making one that handles more than one URL shortner, or one that can be used with custom shortners. And I didn't see an option, but it'd be nice to be able to tie a plug-in, to a blog account; but that's not an issue for plug-ins— more directed at Windows Live Writer dev team. Thanks for your time... Until next time, Larry Henry Jr.