Tuesday, January 11, 2011

Writing a Windows Live Writer Plugin

Well Windows live writer is great but…

1. I really want to be able to see where the <p> tag are placed, since it’s doing some damage to my blog.

2. I really want to add tags more easily

So, I found this post on the web. But once I opened VS I quickly found out that the example was for a previous version or that it didn’t go into the details I required. So I Googled some more and found projects on CodePlex implementing plugins for Windows Live Writer.

I thought to start with the tags project and even gave it the good name of “DllShepherdDotNet.WindowsLiveWriter.TagAdderDeluxe”. I thought it’s going to be easy since I found a project named Windows Live Writer Auto Tag Generator but looking at the source code made me realize fairly quickly that it doesn’t create tags only create a list of tags in the user’s clipboard. A red flag went up in my mind - why didn’t the creators of the plugin add a tag automatically? And the answer to that after looking in the API for WLW - there are no references to Tags anywhere in the API (actually I found one reference in here, with the line: “Ask for confirmation if the Tags/Keywords field is empty.” and I couldn’t find a Tags field!).

I was still not entirely convinced it’s a lost cause, so I tried copy paste the html of the tag - it worked:

<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ad4b3bac-273e-4b93-af2a-ec81181d364b" class="wlWriterEditableSmartContent">del.icio.us Tags: <a href="http://del.icio.us/popular/Windows+live+writer" rel="tag">Windows live writer</a>,<a href="http://del.icio.us/popular/blog" rel="tag">blog</a>,<a href="http://del.icio.us/popular/plugin" rel="tag">plugin</a>,<a href="http://del.icio.us/popular/add-on" rel="tag">add-on</a>,<a href="http://del.icio.us/popular/tag" rel="tag">tag</a>,<a href="http://del.icio.us/popular/paragraph" rel="tag">paragraph</a></div>

The blue bold 0767317B-992E-4b12-91E0-4F059A8CECA8 seems to be the id for tags. Whereas the bold red ad4b3bac-273e-4b93-af2a-ec81181d364b seems to be the id of the tag. So I tried to change the id to something random – it seemed to work until I tried editing it through the Tag dialog, then this happened:

image

I tried restarting WLM the pop up still popped. I tried moving the draft to someplace else and still it popped. At the end a restart solved the problem.

The error report contained the following files:

dwstacktrace.txt

System.NullReferenceException: Object reference not set to an instance of an object.

at WindowsLive.Writer.Mshtml.MshtmlEditor.AddEditDesigner()

at WindowsLive.Writer.Mshtml.MshtmlEditor.ReadyStateChangedHandler(Object sender, EventArgs ea)

 

dwlog.txt

00000 09:18:39:46 PM User is opted out of CEIP

00001 09:18:39:48 PM Starting Windows Live Writer 14.0.8117.416

00002 09:18:39:48 PM .NET version: 2.0.50727.3615

00003 09:18:39:56 PM No legacy directory to monitor for plugins. Ignoring legacy directory.

00004 09:18:40:07 PM 499 499

00005 09:18:41:29 PM Fail Unexpected Error Occurred

Exception Details:

An unexpected error has occurred within the application.

System.NullReferenceException: Object reference not set to an instance of an object.

at WindowsLive.Writer.Mshtml.MshtmlEditor.AddEditDesigner()

at WindowsLive.Writer.Mshtml.MshtmlEditor.ReadyStateChangedHandler(Object sender, EventArgs ea)

//TODO: check out this 

 

After all that, lets work on some paragraphs plugin…

 

 

//TODO: replace WLM with Windows Live Writer

//TODO: copy XML from VS

 

Resources:

MSDN: Windows Live SDK

Writing a simple Windows Live Writer plugin

 

Keywords: Windows live writer, blog, plugin, add-on, tag, paragraph, error, problem, object reference, NullReferenceException,