Lubo Blagoev's Blog

My thoughts on software and technology

Attach File Plugin for Windows Live Writer


[Update:] v.1.2 Fixed changing a file attachment to a new file with the same filename

[Update:] v.1.1 Added a tooltip on long filenames

I wrote a simple plugin for Windows Live Writer. Sidebar support

Attach File Plugin allows you

  • To attach a file into your blog post.
  • Modify attachment properties from WLW Sidebar
  • Include Google tracking code for the attached file.
  • You can upload the files using FTP if you set WLW to use ftp for images.

One important fact Windows Live Writer handles post files very bad. The API and implementation is awful. Test it for yourself . Add a picture to your post. Note in source the href of that picture. Change a property of that picture. (Size, Borders, Wrappings, Margins). Note the href again. Did it change? Yes it did. What happened is that WLW copy the picture every time you change something. You end up with a file name “Me and my girl at the beach[0][1][2][0][9].jpg”. More over they do this on the UI thread. Yes If I want to insert a 25MB picture it gets copied over and over again on the UI thread. It takes 7 seconds right now to get to a blinking cursor from a selected image on my Dual Core 2,4GHz, 4GB RAM machine. I guess they do some serialization of the post at that time. I noticed they call SmartContentSource.GeneratePublishHtml() many times.

It gets worse as you dig in. Plug-ins are able to kill the hosting process by just accessing publishingContext properties in GeneratePublishHtml method.

You can’t post files with spaces in the name and more than certain limit on the filename length. You save a draft post, restart WLW open the draft and voila you have a href to a file “ConcurencyandParallelProgra.txt” instead of the original “Concurency and Parallel Programming.txt”

The docs for Distributing Plugins are wrong. Do not put your registry settings under “HKEY_CURRENT_USER\SOFTWARE\Windows Live\Writer\PluginAssemblies”, instead use “HKEY_CURRENT_USER\SOFTWARE\Windows Live Writer\PluginAssemblies”. They enumerate both paths but load dlls only from the later.

 

That’s the reason I wrote this plugin myself. None of the plug-ins that add files to your post handles these issues. Not even the default Microsoft plug-ins. (Insert Picture) I hope i managed to work around these problems.

Lastly Google PageView option allows you to track downloads of the attached file. Refer to this page for more.

Example: If you set the PageView to “my file” the generated html will be

<a href="http://www.example.com/files/map.pdf" onClick="javascript: pageTracker._trackPageview('my file'); ">

 

Here are the installation packages and source code

 

P.S. I will post the plugin to Windows Live Writer Gallery later since the site is not working right now. (ARGHHHHHH!!!)

Lubo.

Currently rated 3.0 by 2 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

March 8, 2009 17:02 by lubo
Tags: , ,
Categories: