Keyvan Nayyeri

God breathing through me

Write a Windows Live Writer Plugin Using C#

As I stated yesterday Microsoft announced Beta version of its Windows Live Writer a blog client.  Most parts of this client are written in .NET and this enabled everyone to write his own plugins for it.

Today Jayson and I were chatting about lack of Currently Playing song functionality in Live Writer (it's one of cool features in BlogJet and W.Bloggar) and decided to have a competition to write its plugin for Live Writer ourselves.  I started working on Windows Media Player plugin and he worked on Winamp.  He could finish his job and posted about it here.  But I couldn't finish writing that plugin because my Windows Media Player has some problems and I couldn't get its ActiveX reference (AxWMPLib) to work.

However I didn't want to sleep without writing a plugin and tried to write a more useful plugin to add Technorati tags to blog posts.  Here I write about the process I followed to let others start coding for Live Writer.  I created a workspace on CodePlex to write plugins for fun and share them with others.

Background

Technorati tags are a way to index your posts in Technorati index and get more traffic.  You can simply put these tags under your posts via a simple link with rel attribute set to tag.

To start with Live Writer APIs and writing a plugin for it you need to download Live Writer SDK from here.  This package contains a simple demo solution with documents about Live Writer APIs.

Steps to write a plugin for Live Writer

To write a plugin you have three options:

  1. Dialog
  2. Url
  3. Live Clipboard

Latest two options are out of the scope of this post but first one (which is more useful and will be more popular) is what I want to describe here.

To write a Dialog based plugin for Live Writer you have two choices to implement one of them or both:

  1. ContentSource
  2. SmartContentSource

First one is simpler and only adds a link to Insert section/menu of your  Live Writer client application.  SmartContentSource can help you to set more properties for your plugin by putting its visual interface on a section on your client.

In this post I implement a plugin by first choice but writing a plugin by second one isn't very different.

To start coding setup a Windows Class Library and add reference to WindowsLive.Writer.Api DLL file in your project.

Main process of implementation

Class Structure This part is as simple as setting up a class and inherit it from ContentSource base class.  Before coding the main part you can set some attributes for your class such as its identifier, name, image url and ...

You can override some methods to enable different functionality but I just override CreateContent() method.  This method is a function that gets two parameters of IWin32Window and string.  Second parameter is a reference parameter.  This method returns a DialogResult enumerator.  Reference string parameter is a value that you want to embed to your post's body.  By setting this parameter in your method you send it back to Live Writer client to embed it where cursor is placed.  If CreateContent returns Ok as DialogResult value then the string value of second parameter will be embedded in your post's body otherwise it will be ignored.

So what should I do now?  You can create user controls and WinForms for your plugin with your desired UI and options then use some development techniques to get values from user and return them to this method.  This is the simplest form of writing a plugin.  In more complicated cases you can use options to be displayed in your plugin's Options list in Live Writer client and customize the behavior of your plugin based on user's choices.

Here is my Plugin class which is the main body of my plugin.  Other codes are some WinForm codes that aren't necessary to be described here and you can check them by downloading my sample codes.  This plugin simply opens a dialog box and gets the list of space separated tags and embeds them with appropriate link in post's body.

using System;

using System.Collections;

using System.Collections.Generic;

using System.Text;

using WindowsLive.Writer.Api;

using System.Windows.Forms;

 

namespace TechnoratiTagsPlugin

{

    [WriterPluginAttribute

        ("887EC618-8FBE-49a5-A908-2339AF2EC721",

        "Technorati Tags",

        ImagePath = "Images.Technorati.png",

        PublisherUrl = "http://www.nayyeri.net",

        Description = "Helps you to embed Technorati tags in your blog posts")]

 

 

    [InsertableContentSourceAttribute("Technorati Tags")]

    public class Plugin : ContentSource

    {

        public override DialogResult CreateContent(IWin32Window dialogOwner,

            ref string newContent)

        {

            using (InsertForm insertForm = new InsertForm())

            {

                DialogResult result = insertForm.ShowDialog();

                if (result == DialogResult.OK)

                {

                    newContent = this.GetOutput(insertForm.Tags);                   

                }

                return result;

            }

        }

 

        private string GetOutput(List<string> Tags)

        {

            StringBuilder Output = new StringBuilder

                ("<p><strong>Technorati Tags:</strong> ");

            string TagFormat = @"<a href=""http://technorati.com/tag/{0}"" rel=""tag"">{1}</a>";

 

            ArrayList TemporaryOutput = new ArrayList();

 

            foreach (string Tag in Tags)

            {

                TemporaryOutput.Add

                    (string.Format(TagFormat, Tag, Tag));

            }

 

            Output.Append(string.Join(" - ",

                (String[])TemporaryOutput.ToArray(typeof(string))));

            Output.Append("</p>");

            return Output.ToString();

        }

    }

}

Deployment

You need to deploy your project's assmeblies to Plugins subfolder of your Windows Live Writer folder (Usually located at $Drive$\Program Files\Windows Live Writer).  To do this you should add this command to your project's Post-build events:

XCOPY /D /Y /R "$(TargetPath)" "C:\Program Files\Windows Live Writer\Plugins\"

If you don't do this in your project, you need to copy your DLL file manually to that folder.

Once you deploy your project, your plugin will be added to Live Writer and you can start and enjoy using it.

Last point about deployment is if users don't have .NET Framework 2.0 installed on their systems they can't use any plugin that you've written in .NET 2.0.

Result

Here are some snapshots of my plugin.  I'll upgrade it later with more features.

Windows Live Writer Technorati Tags Plugin

Windows Live Writer Technorati Tags Plugin

Windows Live Writer Technorati Tags Plugin

Windows Live Writer Technorati Tags Plugin

Download

You download my plugin with source code from here.

Try it yourself

Start writing plugins for Windows Live Writer and share it with others at our CodePlex workspace.  All our codes are for fun there and you can feel free to join us and write new plugin or modify exisiting one.

47 Comments

ScottGu's Blog
Aug 16, 2006 12:59 AM
#
Earlier this week the Windows Live team released the new Windows Live Writer blog posting and management

Rich Mercer's Blog
Aug 16, 2006 3:50 AM
#
Technorati Tags: Blogging Well it was only released a few days ago, but already there's some interesting

while(availableTime>0) {
Aug 16, 2006 7:04 AM
#
Keyvan Nayyeri created a really cool plugin for Windows Live Writer, the Technorati Tags plugin....

Joe Cheng [MSFT]
Aug 16, 2006 11:01 AM
#
Great stuff. Just a correction, ContentSource is simpler than SmartContentSource, I know you know this but in "Steps to write a plugin for Live Writer" you have it stated the other way around.

Keyvan Nayyeri
Aug 16, 2006 11:43 AM
#

Sure,

Thanks for pointing it :-)

Corrected.


TrackBack
Aug 16, 2006 11:56 AM
#

(via ScottGu)

Keyvan gives a nice intro to writing plugins in C# ...

Keyvan Nayyeri
Aug 16, 2006 12:38 PM
#
In my previous post I introduced our new workspace on CodePlex for writing Windows Live Writer plugins

Community Server Daily News
Aug 16, 2006 1:16 PM
#
news of the day a grab bag for what's happening in Community Server Keyvan Nayyeri walks us through the

deedee.brainstream.net
Aug 16, 2006 2:18 PM
#

Blog::David
Aug 16, 2006 4:06 PM
#
Keyvan Nayyeri nous montre comment écrire un plugin en C# pour WLW, cet article est fort intéressant

TrackBack
Aug 16, 2006 8:53 PM
#
The latest plugin I’ve got for WLW is one to insert Technorati Tags into the bottom of a post ...

TrackBack
Aug 17, 2006 2:14 PM
#

Hi,

I'm just testing out Windows Live Writer ...


Bryant Likes's Blog
Aug 17, 2006 6:56 PM
#
Via Greg : Feeds.com - Write a Windows Live Writer plugin using C# However I didn't want to sleep without

Bryant Likes's Blog
Aug 17, 2006 7:55 PM
#
If you copy source as html (or have any html in the clipboard), hitting paste in Windows Live Writer

TrackBack
Aug 17, 2006 8:54 PM
#
C#Feeds.com - Write a Windows Live Writer plugin using C# ...

Mac
Aug 18, 2006 12:36 PM
#
Hello, your post is very useful to me. I try to write a Writer plugin, but i dont know how to debug a plugin componet in my Visual Studio 2005 Express. Could you give me some advice? thx

Keyvan Nayyeri
Aug 18, 2006 1:03 PM
#
Mac, The best approach you can follow for debug (for normal developers) is to build and test your plugin. What you need is adding the command I provided in Deployment section of my post to your project's Post-build events then rebuild your project and launch Windows Live Writer and test your changes there. This is for amateur solution. If you're familiar with any unit test approach you can follow it.

Community Server Daily News
Aug 18, 2006 1:04 PM
#
news of the day a grab bag for what's happening in Community Server Sean Winstead grabs today's top news

Mac
Aug 18, 2006 4:43 PM
#
Hi Keyvan, thanks for your answer, actually I need to debug my plugin in "step in" mode like normally to debug a .exe project. But in Visual Studio 2005 Express I haven't found any settings like "Start Action" to set a hosting program for this .DLL, perhalps this cheap version doesn't support any no-basic featrue.

Keyvan Nayyeri
Aug 18, 2006 11:50 PM
#
Mac, Actually I don't know much about VS Express limitations. Hopefully someone who has worked more with it can help you.

Thomas Freudenberg's Blog
Aug 21, 2006 7:33 PM
#
I just want to note that my last post was brought to you by Windows Live Writer and Code Syntax Highlighter

Andrej Tozon's blog
Aug 22, 2006 8:58 AM
#
... for my Windows Live Writer post... I just love this tool. A bunch of helpful add-ins are already

Mike Ormond's WebLog
Aug 24, 2006 5:20 AM
#
I have to confess that I didn't plan to install Live Writer - I was quite happy with blogging from Word...

TrackBack
Aug 26, 2006 7:52 AM
#
We're excited to announce that in late September, there will be a new section for Windows Live Writer plugins on the Windows Live Gallery that will allow developers

Keyvan Nayyeri
Aug 26, 2006 9:02 AM
#
Microsoft announced a program to gather all Windows Live Writer plugins and publish them on Live Gallery

Windows Live
Aug 30, 2006 1:27 AM
#
Thomas J. points to a number of new Gadgets for Spaces , including Hangman and Pong, a Mortgage rates

External News
Aug 30, 2006 2:53 AM
#
Thomas J. points to a number of new Gadgets for Spaces , including Hangman and Pong, a Mortgage rates

Keyvan Nayyeri
Sep 04, 2006 1:42 AM
#
Today our Windows Live Writer Plugins project hits its first public release, codenamed Cyclone (I inspired

Microsoft Daily News
Sep 10, 2006 5:37 AM
#
Thomas J. points to a number of new Gadgets for Spaces , including Hangman and Pong, a Mortgage rates

Shannon Braun's Weblog
Sep 18, 2006 10:05 PM
#

Keyvan Nayyeri
Dec 07, 2006 10:04 AM
#
We're close to a new release of our Windows Live Writer plugins project and I wanted to add a new plugin

Keyvan Nayyeri
Dec 11, 2006 8:03 AM
#

I'm pleased to announce the second version of our Windows Live Writer plugins collection, codenamed Gustnado.


Il Blog di Nicol
Jan 17, 2007 3:15 AM
#
PingBack from http://www.technacular.com/2007/02/04/tool-to-create-compelling-blog-posts-easily/

Archies
Mar 11, 2007 10:46 AM
#
Hi Keyvan Nayyeri...just read ur blog..I am a comuter graduate and I am currently working on a samll project in which I have to make plugins for Media Player using C#...if you could plz help me in this regard..as I am not able to initiate my project....

Rahul Soni
Apr 19, 2007 10:36 PM
#
I thought of posting this link about a similar stuff in VB.NET. http://blogs.msdn.com/rahulso/archive/2007/04/16/create-windows-live-writer-plugin-in-visual-basic-net.aspx Regards, Rahul

Rahul Soni
Apr 26, 2007 2:16 AM
#
Hi, First of all, I would like to thank you for your WLW plugin in C#. Since I am not from a C# background, I used a similar logic to create it in VB.NET and also created a WLW Plugin to insert smileys. You can have it here... http://blogs.msdn.com/rahulso/archive/tags/Windows+Live+Writer/default.aspx Thanks, Rahul

sindhu
Jun 24, 2007 12:31 AM
#
hi! i love the post you've written here. just what i wanted. although i do not know C++ i will give this a try, as i know C. but i want to know, if it is possible to write a plugin that will help users edit text in "web preview mode" in live writer? because i like it better that way. please do reply. thanks :)

piQM
Jul 04, 2007 3:33 PM
#
its not easy to find out the livewriter start parameters. Write a Windows Live Writer plugin using C# - Keyvan Nayyeri

Keyvan Nayyeri
Nov 08, 2007 10:38 PM
#
It's been over a year since the first release of Windows Live Writer . In August 2006, this new Live

Alireza
Dec 26, 2007 3:04 PM
#

Hi Mr. Nayyeri

Windows Live Writer is great tool but again IT monsters forgot Right-to-Left writers in world and did not put a button for it! Just a Align Right or Left button there is in WLW.

Would you help millions of Persian, Hebrew, Arabic, Urdu, Peshu, etc. language writers and make a Plugin for "Right-to-Left" button?

Regards

AlizzA


Tony
Apr 06, 2008 11:18 PM
#

hi, I was attempting to write a small program for my website www.NewsForNatives.com but it only works in theory, when I compile it i get an error, it is so frustrating! but your tutorial is helping, thanks!

Pingback from ???????????????? ???????????????? ?????? Windows Live Writer

Pingback from Windows Live Writer plugin to prevent internal pingbacks on Wordpress.com « User Interface - it matters


Steve Dunn
Mar 13, 2009 8:53 AM
#

Hi,

I've just updated my Code Formatter Plugin. Version 2.0.0.1 now supports the ActiPro Syntax Highlighter output and also the popular JavaScript SyntaxHighlighter output. stevedunns.googlepages.com/.../codeformatterfo


Shailesh
Dec 18, 2009 4:25 AM
#

In Above Code I am getting error in this line
InsertForm insertForm = new InsertForm()

And When i try to download it ... it showing a message page does not exisist

So please send me a link from where i can download complete code.

Also I wnt to make plugin for photo album upload on my own site so if anyone has idea on that then also please give me some hint.
Thanks


svora
Jan 04, 2010 4:04 AM
#

Hi
can anyone give me a solution of this
http://social.msdn.microsoft.com/Forums/en/wlwdev/thread/f555955a-b96d-4e13-a078-f12df240393d

this has been developed using smartcontentsource-class-generatehtml method

Leave a Comment





Ads Powered by Lake Quincy Media Network