How to Create Plugin for Windows Live Writer? Simple Content Source.
Windows Live Writer gives capability to extend functionality by creating new plug-ins.
What I will demonstrate here is how to create content source plug-in which inserts custom formatted content.
There are two types of content sources available in writer:
- Simple Content Source
- Smart Content Source
Simple Content Source:
Enables to insert custom HTML code to the post.
Smart Content Source:
Enables to insert custom HTML content with "smart" editing capabilities, such as include atomic selection, two-way editing using the Sidebar, resizability.
In this blog post I'll demonstrate how to create Simple content source plug-in.
Content Source Plugin
Create Project in Visual Studio
First of all we have to create Class Library project in Visual Studio.
This demo has been done by Visual Studio 2005 and .Net Framework 2.0
Next, we have to add reference to C:\Program Files\Windows Live\Writer\WindowsLive.Writer.Api.dll library. Library contains classes which we will use for for plug-in implementation.
Set property "Copy Local" of added reference to false. It will stop copying to destination folder all libraries required for WindowsLive.Writer.Api.dll.
Create Class
Now it is time to implement class which will contain implementation of plug-in.
Attributes
Create a new class and cover it by WindowsLive.Writer.Api.WriterPluginAttribute.
WriterPluginAttribute's constructor accepts two input parameters: GUID and Name. Both require to unify plug-in in the list of all plugins in Live Writer.
Note: There is also "imagepath" parameter which defines path to the image file which can be used as an icon but currently it marks as "Obsolete" therefor I'll skip this part for now.
There are three features which can be overridden in both Simple and Smart content sources:
- Insert content from Dialog box
- Insert content from Clipboard
- Insert content from URL
In this demo we will write plug-in which uses "Insert content from Dialog box" functionality. To achieve that we have to cover class by WindowsLive.Writer.Api.InsertableContentSourceAttribute attribute.
Note: To implement "Insert content from Clipboard" or "Insert content from URL" class should be covered by LiveClipboardContentSourceAttribute or UrlContentSourceAttribute respectively.
Attributes notify Live Writer that plug-in contains implantation of "Insert" functionality.
Constructor of InsertableContentSourceAttribute class require at least one input parameter which is title of plug-in shown on "Insert" list.
using WindowsLive.Writer.Api;
namespace HyperlinkBuilder
{
[WriterPlugin("ad23cf0b-5cf2-441d-a0d7-7ee3fdc4ff55", "HyperlinkBuilder")]
[InsertableContentSource("Hyperlink to content.")]
public class LinkContainer
{
}
}
HyperlinkContainerEditor
For demo let's create plug-in which will insert hyperlink to the content.
First we'll create a editor with three textboxes which allows to add URL, Text and Title of hyperlink. Due to fact that dialog box (editor) based on windows form, we have to add reference to System.Windows.Forms.dll library.
Now let's implement editor. It basically contains three textboxes (URL, Text, Title) and two buttons (OK, Cancel).
using System.Windows.Forms;
namespace DotNetStyling.LiveWriterPlugins.HyperlinkBuilder
{
public partial class HyperlinkBuilderEditor : Form
{
public HyperlinkBuilderEditor()
{
InitializeComponent();
this.txtURL.Focus();
}
public string HyperlinkTitle
{
get { return txtTitle.Text; }
}
public string HyperlinkURL
{
get { return txtURL.Text; }
}
public string HyperlinkText
{
get { return txtText.Text; }
}
}
}
ContentSource base class
To implement Simple Content we have to inherit class from WindowsLive.Writer.ContentSource and overrite one of its member:
To implement "Insert Content from Dialog Box" we have to override CreateContent method.
Note: For implementation "Create from Clipboard" or "Create Content From URL" functionality we have to override CreateContentFromLiveClipboard and CreateContentFromUrl methods respectively.
using System.Text;
using WindowsLive.Writer.Api;
using System.Windows.Forms;
namespace DotNetStyling.LiveWriterPlugins.LinkContainer
{
[WriterPlugin("ad23cf0b-5cf2-441d-a0d7-7ee3fdc4ff55", "HyperlinkBuilder")]
[InsertableContentSource("Hyperlink to content.")]
public class HyperlinkBuilder: ContentSource
{
public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content)
{
DialogResult dialogResult;
HyperlinkContainerEditor editor = new HyperlinkContainerEditor();
dialogResult = editor.ShowDialog();
if(dialogResult==DialogResult.OK)
{
content = PrepareHyperlink(editor.HyperlinkText,
editor.HyperlinkURL,
editor.HyperlinkTitle);
}
return dialogResult;
}
private string PrepareHyperlink(
string text,
string url,
string title)
{
StringBuilder formattedHyperlink = new StringBuilder(256);
formattedHyperlink.AppendFormat(
"<a href='{0}' title='{1}'>{2}</a>",
url,
title,
text);
return formattedHyperlink.ToString();
}
}
}
Basically that's it. To simplify demonstration I will skip Validating input parameter or other UX features.
Deploy
- Build a project.
- Copy compiled file to the C:\Program Files\Windows Live\Writer\Plugins\ folder
- Run Windows Live Writer
In the list of insert features there is implemented plug-in.
How to use
- Click on "Insert Hyperlink to content".
- Click "OK" and you will see generated hyperlink in the content.
How to debug ?
I assume it will be required to debug the code.
These are steps how we can achieve that.
- Compile the code in debug mode.
- Copy compiled dll with its pdb file to destination folder (C:\Program Files\Windows Live\Writer\Plugins\).
- Then open Visual Studio and set a breakpoint in any place you need.

- Run Windows Live Writer
- Attach debugger to Windows Live Writer process in Visual Studio.
- Run plug-in in Live Writer.
Application will break in the line where breakpoint has been set.