Writing Plugins For Windows Live Writer – Getting Started

By ScottIsAFool | In Developer | Posted October 3, 2006 1 comment
Hi, I’m Scøtt, or ScottIsAFool as a lot of you know me as smile_regular. Over the next series of blog entries, I will guide you through the process of making a plugin for Windows Live Writer.
In this article, I am going to show how to create a simple plugin for Windows Live Writer, starting from the beginning. Writing plugins for Live Writer is simple enough, but sometimes you just need a little helping hand, and I’m speaking from experience smile_regular.
First off, you will need to make sure that you have the required programs. Make sure that you have the following installed:
  • Windows Live Writer – download
  • Microsoft .NET Framework v2.0 – download
  • Visual Studio Express C# Edition – download (this link takes you to an installer that will require you to download the rest of the files).
Once you have installed them then we are ready to go. Open Visual Studio and start a new project, selecting Class Library andgive the plugin a name. For this example, I will call it MyNewPlugin.
Now we need to tell the plugin to look at the Windows Live Writer API. In the Solution Explorer on the right hand side, right click on the References folder and select ‘Add Reference’ and browse to the Live Writer folder in your Program Files folder. The dll we want is WindowsLive.Writer.API.dll:
Now that the reference has been create we need to tell the plugin to actually use the APIs, so we need to add
using WindowsLive.Writer.Api;
You should also add the reference for Windows Forms. So, following the same procedure we have just done, add the System.Windows.Forms reference from the .NET section, and again tell the plugin that we need to use it
using System.Windows.Forms;
Next we need to set the plugin’s attributes:
    [WriterPlugin("8638eda4-6533-4d19-9da7-ff92ff5a7590","My First Plugin",
        Description="This is my first plugin",
        HasEditableOptions=false,
        Name="My First Plugin",
        PublisherUrl="http://scottisafool.spaces.live.com")]
 
Now, the first thing you see in those attributes is the GUID (the combination of numbers and letters), this is unique to each plugin that you make. To get the GUID for your project, right click on the project name in the Solution Explorer and click on properties, then click on the Assembly Information button in the next screen:
The second string is the text that will appear in Live Writer’s Plugins section in the Options; the Description is what appears underneath the list of plugins when you have clicked on your plugin in the options of Live Writer; HasEditableOptions is either true or false and this tells Live Writer whether to put an options button in the Plugin options (for most plugins you probably won’t need this set to true, and you certainly don’t for this example); PublisherUrl is where you put the link to your site.
Underneath the WriterPlugin code, we need to set what text appears in the Insert section. So we use the code:
[InsertableContentSource(“From MyNewPlugin“)]
Time to declare the plugin’s main class
public class NewPlugin : ContentSource
    {
        public NewPlugin()
        {
        }
Note: after declaring the public class, you must call that class, but keep it empty as in the example above. 
Next we need to override the main class (this is why it was left blank), and we put in the following code: 
public override DialogResult CreateContent(IWin32Window dialogOwner, ref string newContent)
        {
The ref string newContent is what actually gets put back into the blog entry, so we need to set that to equal something:
newContent = "This was put in by my first Live Writer Plugin :)";
Because of how the override works, we need to return a DialogResult of OK (I will go into this in more detail in another post), so we simply put in:
return DialogResult.OK;
Close off anything that is open (ie, }). That is your plugin written, now we need to build it. Before we do though, we should add a command into the post-build section. So, right click on your plugin name in the Solution Explorer and click on properties. Select the Build Events section and copy the following command into the post-build event section:
XCOPY /D /Y /R “$(TargetPath)” “C:Program FilesWindows Live WriterPlugins”
Now we are ready to build the plugin. Hit F6 on your keyboard and watch the fun begin smile_regular. Once the build has finished successfully, open up Windows Live Writer and in the Insert section, you will see your link:
Click it and you will see the text we set for newContent is now in your blog entry. So we have now created a basic plugin for Windows Live Writer
Download the sourcecode for this example here.
Next time I will talk you through how to add an image to your link.
SL

Next – Adding An Icon >>

Posted October 3rd, 2006 at 10:29 pm
Category: Developer
Tags: How To, SDK, Writer
  • http://www.darrenstraight.com/blog Darren Straight

    Nice one Scott! :)