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!
- Start by creating a new Class Library project. Make sure to target the project to .NET Framework 2.0.
- 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
- Add a reference to the .NET 2.0 System.Windows.Forms library.
- Rename your Class1.cs file to MyBitlyTweeterPlugin.cs
- Open MyBitlyTweeterPlugin.cs and add a using directive for System.Windows.Forms and WindowsLive.Writer.Api. This gives you access to the Writer API.
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:
Adorn your class with the WriterPluginAttribute attribute using the GUID you generated.