I'm Keyvan Nayyeri, a 25 years old Ph.D. student at
the Computer Science department of
the University of Texas at San Antonio.
I'm also
a Software Architect and Developer and previously held a B.Sc.
degree in Applied Mathematics.
This is my blog where I publish content about various topics specifically Programming Languages and Compilers, Software
Engineering and Programming.
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.
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.
To write a plugin you have three options:
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:
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.
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();
}
}
}
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.
Here are some snapshots of my plugin. I'll upgrade it later with more features.
You download my plugin with source code from here.
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.
ScottGu's Blog
Aug 16, 2006 12:59 AM
#
Rich Mercer's Blog
Aug 16, 2006 3:50 AM
#
while(availableTime>0) {
Aug 16, 2006 7:04 AM
#
Joe Cheng [MSFT]
Aug 16, 2006 11:01 AM
#
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
#
Community Server Daily News
Aug 16, 2006 1:16 PM
#
deedee.brainstream.net
Aug 16, 2006 2:18 PM
#
Blog::David
Aug 16, 2006 4:06 PM
#
TrackBack
Aug 16, 2006 8:53 PM
#
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
#
Bryant Likes's Blog
Aug 17, 2006 7:55 PM
#
TrackBack
Aug 17, 2006 8:54 PM
#
Mac
Aug 18, 2006 12:36 PM
#
Keyvan Nayyeri
Aug 18, 2006 1:03 PM
#
Community Server Daily News
Aug 18, 2006 1:04 PM
#
Mac
Aug 18, 2006 4:43 PM
#
Keyvan Nayyeri
Aug 18, 2006 11:50 PM
#
Thomas Freudenberg's Blog
Aug 21, 2006 7:33 PM
#
Andrej Tozon's blog
Aug 22, 2006 8:58 AM
#
Mike Ormond's WebLog
Aug 24, 2006 5:20 AM
#
TrackBack
Aug 26, 2006 7:52 AM
#
Keyvan Nayyeri
Aug 26, 2006 9:02 AM
#
Windows Live
Aug 30, 2006 1:27 AM
#
External News
Aug 30, 2006 2:53 AM
#
Keyvan Nayyeri
Sep 04, 2006 1:42 AM
#
Microsoft Daily News
Sep 10, 2006 5:37 AM
#
Shannon Braun's Weblog
Sep 18, 2006 10:05 PM
#
Keyvan Nayyeri
Dec 07, 2006 10:04 AM
#
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
#
Tool To Create Compelling Blog Posts Easily
Feb 04, 2007 8:17 PM
#
Archies
Mar 11, 2007 10:46 AM
#
Rahul Soni
Apr 19, 2007 10:36 PM
#
Rahul Soni
Apr 26, 2007 2:16 AM
#
sindhu
Jun 24, 2007 12:31 AM
#
piQM
Jul 04, 2007 3:33 PM
#
Keyvan Nayyeri
Nov 08, 2007 10:38 PM
#
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!
???????????????? ???????????????? ?????? Windows Live Writer
Jan 17, 2009 12:13 PM
#
Pingback from ???????????????? ???????????????? ?????? Windows Live Writer
Windows Live Writer plugin to prevent internal pingbacks on Wordpress.com « User Interface - it matters
Jan 20, 2009 7:08 PM
#
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