Developing Plugins for Windows Live Writer Plugins for Windows Live Writer are simple to create and can provide many extra features. This article will show you how to start writing plugins for Windows Live Writer, including how to get started, how to debug, and how to package the final plugin. Before you can begin writing a plugin for Windows Live Writer (http://writer.live.com/), you need to understand what it is and what it actually does. Windows Live Writer is a free desktop blog authoring tool from Microsoft that allows you to write an entry for your blog without having to be online and do it right from your desktop. Live Writer doesn’t just support Microsoft’s own blogging site (Windows Live Spaces), it supports a multitude of different blog engines: basically any that support the MetaWeblog API or Atom Publishing Protocol. This list includes Wordpress, Community Server, LiveJournal, and Blogger. You can write your blog entry in the style of your own blog as well because Live Writer downloads your blog style and uses it as a template. | " | Settings, like Forms, can be an integral part of your plugin if you would like the user to be able to set defaults for the plugin.
| " |
Whether you’re someone just starting out with their first blog, or a seasoned pro, Windows Live Writer makes the blogging experience that much better. And the features that don’t come with the program can come in the form of plugins that add extra extensibility and improve the blogging experience even more. Your Development Environment Pre-requisites Live Writer plugins are written in .NET, but while you can use .NET 1.1, it is recommended to use .NET 2.0. You will need Visual Studio 2005 or above installed-this can be any version of Visual Studio 2005 or 2008 (http://msdn.microsoft.com/vstudio), including the free Express Editions of Visual Studio (http://www.microsoft.com/express/). You will also need to download Windows Live Writer (http://writer.live.com/) as this has the required API DLL on which the plugins are based. As plugins are developed in .NET, you can use any language that uses it, but for my examples, I will be using C#. Writing Your Plugin Open up Visual Studio and create a new Class Library project, giving it a meaningful name for your plugin. Rename the default class1.cs to plugin.cs (this isn’t essential, but will allow you to quickly see the main plugin class). Next you need to add the Windows Live Writer API reference: bring up the Add Reference window, point to your Windows Live Writer install folder (typically C:\Program Files\Windows Live\Writer\), and then select WindowsLive.Writer.API.dll. As a best practice for this reference, set the property of Copy Local to be false for this reference (this will stop older versions of the API DLL being copied into the Live Writer Plugins folder). Open plugin.cs and include the following using statement: using WindowsLive.Writer.Api;
You also need to add a reference to the Windows Forms namespace, so add System.Windows.Forms as a reference and also include the following: using System.Windows.Forms;
Now you can add the Plugin’s attributes: these tell Live Writer about who made the plugin, the link to the developer’s Web site, the description, whether the plugin has options, and the location of the image to be used as the plugin’s icon within the Live Writer UI. These details go in just after the namespace (before the main class). The code for this is as follows: [WriterPlugin ("d39bba2b-9522-49b1-8731-61030ccd6c95", "My First Plugin", Description = "This is my first plugin", HasEditableOptions = false, Name = "My First Plugin", PublisherUrl = "http://www.liveside.net")] [InsertableContentSource ("Bold Text")]
Please note: The GUID is unique for each plugin and you shouldn’t reuse it in other plugins as this can cause problems for Writer and may cause your plugin not to be loaded. To add an icon for your plugin, you should include the code: ImagePath = "icon.gif",
The value of this attribute must be the file name of the icon you wish to use. Its location is relative to where it is stored in your project. The image itself must be 20 x 18 pixels in size. After this, you need to create your plugin class. The plugin class has to inherit from the Live Writer API and there are two choices to inherit from: ContentSource and SmartContentSource. ContentSource plugins are very basic plugins and will only insert text into the blog entry. The plugin cannot change that text again. SmartContentSource plugins can do a lot more and will be covered later on in the article. For this example, I am going to inherit just from the ContentSource interface: public class LiveWriterExamplePlugin : ContentSource
Then you need to include how the plugin will insert the text. There are three different types: - CreateContent (from the Insert menu).
- CreateContentFromUrl (when pasting a URL into the blog entry area or from a Blog This action).
- CreateContentFromLiveClipboard (using the LiveClipboard, although this method isn’t widely used as there isn’t much LiveClipboard content out there due to documentation).
CreateContent is the most commonly used method, although there are examples where the FromUrl method has been used. The plugin code overrides all of these methods and they are not mutually exclusive; you can have more than one type in a plugin. Override CreateContent Method You can see that there is a string reference of content. There are two things of note about this reference: - The initial value of content is whatever may have been highlighted in the editing window. If no text was highlighted, then content will be empty, if you had text highlighted, then the full HTML code will be what content equals.
- Whatever content is equal to, that is what will be put back into the blog entry. This must include any HTML formatting that might be required for the plugin’s functionality.
Remove the base code that is put in, this is just a placeholder. To start off with, for this first example, just return DialogResult.OK. This first part will just be a simple plugin to make the highlighted text bold, so the code for the CreateContent method is simply: public override DialogResult CreateContent (IWin32Window dialogOwner, ref string content) { if (!string.IsNullOrEmpty(content)) content = string.Format("<b>{0}</b>", content); return DialogResult.OK; }
Using this code, the plugin will take in whatever text was highlighted and the bold HTML tags to either end of that content. Listing 1 shows just how simple the code can be for a Live Writer plugin. | & | | 
By: Scøtt Lovegrove
Scøtt is a Windows Live MVP for Microsoft and is very heavily involved with Windows Live, not just with Windows Live Writer. He is one of the main writers for LiveSide.net, a community Web site dedicated to Windows Live and his main area of blogging for LiveSide is developing on Windows Live.
Scøtt has written a number of popular plugins for Windows Live Writer and can often be found in the Live Writer Support forum, for both general support and the developer forums.
scott@liveside.net | Fast Facts | | Windows Live Writer doesn’t just support Microsoft’s own Windows Live Spaces blogging platform, it supports a number of different and popular blog engines, such as Wordpress or Community Server. | |
|