Live Writer “Hello World” Plug-in

I started using Windows Live Writer a couple of months ago and I think that it is a fantastic tool.  One benefit is its easy extensibility via easy to write plug-ins in .NET.

Whenever I blog about a book, I like to display the book’s cover image and a link to Amazon.com but also to Amazon.ca.  I needed to go to the Amazon Websites, search for the books in the associates section, copy paste the generated HTML.  Not very long but still, how about automating this?

I started searching Live Writer plug-in development and quickly found a link to a SDK and a Channel 9 video.  An hour later I had a fully functional plug-in that saves me approximately 124.6 seconds each time I need to paste some book references to Amazon.

Here’s the code for a simple “Hello World”

1-Start a new project in Visual Studio and select Class Library.

2-Reference this Live Writer DLL:
C:\Program Files\Windows Live\Writer\WindowsLive.Writer.Api.dll

3-This C# code will insert the “Hello World” string at the cursor position when the user clicks on the plug-in link either from the right side action pane or from the Insert menu.

using WindowsLive.Writer.Api;
[WriterPlugin("Generate and insert a GUID here", "Hello World", PublisherUrl = "http://guy.dotnet-expertise.com", Description = "Hello World")]
[InsertableContentSource("Hello World", SidebarText = "Hello World")]
public class LiveWriterHelloWorldPlugin : ContentSource
{
    public override System.Windows.Forms.DialogResult CreateContent(System.Windows.Forms.IWin32Window dialogOwner, ref string content)
    {
        content = "Hello World";
        return DialogResult.OK;
     }
}

4-Copy the DLL in the plug-in folder:
C:\Program Files\Windows Live\Writer\Plugins

No Comments