Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET 4.5
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Amazon Web Services
Analysis Services
Android
Architecture
Arduino
ASP .NET Web API
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
BDD
Big Data
Bing
BizTalk
Book Excerpts
Build and Deploy
Business Intelligence
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE Framework Info - non Technical
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Debugger
Design Patterns
Development Process
Display Technologies
Distributed Computing
Document Database
DotNetNuke
DSL
Dynamic Languages
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
HTML 5
Internet Explorer 8.0
Interviews
IOS
iPhone
Iron Ruby
Java
Java Script
JavaScript
jQuery
JSON
Lightswitch
LINQ
Linux
LUA
Mac OS X
MDX
Messaging
Metro
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
MVVM
MySQL
Network
NHibernate
node.js
NOSQL
Nuget
Object Oriented Development
Objective C
Odata
OLAP
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
PHP
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Prolog
Python
Q&A
Rails
Rake
Razor
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Scheme
Search
Security
Services
SharePoint
SignalR
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server 2012
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
TFS
Tips
TypeScript
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 11
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio 2011
Visual Studio 2012
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WebMatrix
WF
Whitepapers
Windows 7
Windows 8
Windows Azure
Windows Live
Windows Phone 7
Windows Phone SDK
Windows Server
Windows Vista
WinForms
WinRT
Workflow
WPF
XAML
Xiine Documentation
XML
XNA
XSLT



LearnNow


XAMALOT
 


LearnNow

Reader rating:
Click here to read 3 comments about this article.
Article source: CoDe (2008 - Vol. 5 - Issue 2 - Windows Live )


Article Pages:  1  2 3 - Next >


Developing Plugins for Windows Live Writer

Plugins for Windows Live Writer are simple to create and can provide many extra features. This article will show you how to start writing plugins for Windows Live Writer, including how to get started, how to debug, and how to package the final plugin.

Before you can begin writing a plugin for Windows Live Writer (http://writer.live.com/), you need to understand what it is and what it actually does. Windows Live Writer is a free desktop blog authoring tool from Microsoft that allows you to write an entry for your blog without having to be online and do it right from your desktop. Live Writer doesn’t just support Microsoft’s own blogging site (Windows Live Spaces), it supports a multitude of different blog engines: basically any that support the MetaWeblog API or Atom Publishing Protocol. This list includes Wordpress, Community Server, LiveJournal, and Blogger. You can write your blog entry in the style of your own blog as well because Live Writer downloads your blog style and uses it as a template.

"
Settings, like Forms, can be an integral part of your plugin if you would like the user to be able to set defaults for the plugin.
"

Whether you’re someone just starting out with their first blog, or a seasoned pro, Windows Live Writer makes the blogging experience that much better. And the features that don’t come with the program can come in the form of plugins that add extra extensibility and improve the blogging experience even more.

Your Development Environment Pre-requisites

Live Writer plugins are written in .NET, but while you can use .NET 1.1, it is recommended to use .NET 2.0. You will need Visual Studio 2005 or above installed-this can be any version of Visual Studio 2005 or 2008 (http://msdn.microsoft.com/vstudio), including the free Express Editions of Visual Studio (http://www.microsoft.com/express/). You will also need to download Windows Live Writer (http://writer.live.com/) as this has the required API DLL on which the plugins are based.

As plugins are developed in .NET, you can use any language that uses it, but for my examples, I will be using C#.

Writing Your Plugin

Open up Visual Studio and create a new Class Library project, giving it a meaningful name for your plugin. Rename the default class1.cs to plugin.cs (this isn’t essential, but will allow you to quickly see the main plugin class).

Next you need to add the Windows Live Writer API reference: bring up the Add Reference window, point to your Windows Live Writer install folder (typically C:\Program Files\Windows Live\Writer\), and then select WindowsLive.Writer.API.dll. As a best practice for this reference, set the property of Copy Local to be false for this reference (this will stop older versions of the API DLL being copied into the Live Writer Plugins folder). Open plugin.cs and include the following using statement:

using WindowsLive.Writer.Api;

You also need to add a reference to the Windows Forms namespace, so add System.Windows.Forms as a reference and also include the following:

using System.Windows.Forms;

Now you can add the Plugin’s attributes: these tell Live Writer about who made the plugin, the link to the developer’s Web site, the description, whether the plugin has options, and the location of the image to be used as the plugin’s icon within the Live Writer UI. These details go in just after the namespace (before the main class).

The code for this is as follows:

[WriterPlugin ("d39bba2b-9522-49b1-8731-61030ccd6c95",
    "My First Plugin",
    Description = "This is my first plugin",
    HasEditableOptions = false,
    Name = "My First Plugin",
    PublisherUrl = "http://www.liveside.net")]
[InsertableContentSource ("Bold Text")]

Please note: The GUID is unique for each plugin and you shouldn’t reuse it in other plugins as this can cause problems for Writer and may cause your plugin not to be loaded.

To add an icon for your plugin, you should include the code:

ImagePath = "icon.gif",

The value of this attribute must be the file name of the icon you wish to use. Its location is relative to where it is stored in your project. The image itself must be 20 x 18 pixels in size.

After this, you need to create your plugin class. The plugin class has to inherit from the Live Writer API and there are two choices to inherit from: ContentSource and SmartContentSource. ContentSource plugins are very basic plugins and will only insert text into the blog entry. The plugin cannot change that text again. SmartContentSource plugins can do a lot more and will be covered later on in the article. For this example, I am going to inherit just from the ContentSource interface:

public class LiveWriterExamplePlugin : ContentSource

Then you need to include how the plugin will insert the text. There are three different types:

  • CreateContent (from the Insert menu).
  • CreateContentFromUrl (when pasting a URL into the blog entry area or from a Blog This action).
  • CreateContentFromLiveClipboard (using the LiveClipboard, although this method isn’t widely used as there isn’t much LiveClipboard content out there due to documentation).

CreateContent is the most commonly used method, although there are examples where the FromUrl method has been used. The plugin code overrides all of these methods and they are not mutually exclusive; you can have more than one type in a plugin.

Override CreateContent Method

You can see that there is a string reference of content. There are two things of note about this reference:

  1. The initial value of content is whatever may have been highlighted in the editing window. If no text was highlighted, then content will be empty, if you had text highlighted, then the full HTML code will be what content equals.
  2. Whatever content is equal to, that is what will be put back into the blog entry. This must include any HTML formatting that might be required for the plugin’s functionality.

Remove the base code that is put in, this is just a placeholder. To start off with, for this first example, just return DialogResult.OK. This first part will just be a simple plugin to make the highlighted text bold, so the code for the CreateContent method is simply:

public override DialogResult CreateContent
            (IWin32Window dialogOwner, 
 ref string content)
{
       if (!string.IsNullOrEmpty(content))
           content = 
string.Format("<b>{0}</b>", content);
       return DialogResult.OK;
}

Using this code, the plugin will take in whatever text was highlighted and the bold HTML tags to either end of that content. Listing 1 shows just how simple the code can be for a Live Writer plugin.

&

By: Scøtt Lovegrove

Scøtt is a Windows Live MVP for Microsoft and is very heavily involved with Windows Live, not just with Windows Live Writer. He is one of the main writers for LiveSide.net, a community Web site dedicated to Windows Live and his main area of blogging for LiveSide is developing on Windows Live.

Scøtt has written a number of popular plugins for Windows Live Writer and can often be found in the Live Writer Support forum, for both general support and the developer forums.

scott@liveside.net

Fast Facts

Windows Live Writer doesn’t just support Microsoft’s own Windows Live Spaces blogging platform, it supports a number of different and popular blog engines, such as Wordpress or Community Server.



Listing 1: Full code for a very basic Live Writer plugin.
using System;
using System.Collections.Generic;
using System.Text;
using WindowsLive.Writer.Api;
using System.Windows.Forms;

namespace LiveWriterExample
{
    [WriterPlugin("d2c99304-8648-4696-9ef1-6a82a2d070c9", 
        "LiveWriterExamplePlugin",
        Description = "Makes highlighted text bold.",
        HasEditableOptions = true,
        ImagePath = "icon.gif",
        Name = "Bold Text Plugin",
        PublisherUrl = "http://www.liveside.net")]
    [InsertableContentSource("Bold Text")]

    public class LiveWriterExamplePlugin : ContentSource
    {
        public override DialogResult CreateContent
            (IWin32Window dialogOwner, ref string content)
        {
            // If nothing is highlighted, content will be empty.
            // If this is the case, the plugin does nothing.
            if (!string.IsNullOrEmpty(content))
                content = string.Format("<b>{0}</b>", content);
            
            return DialogResult.OK;
        }

    }
}


Article Pages:  1  2 3 - Next Page: 'Compiling and Debugging' >>

Page 1: Developing Plugins for Windows Live Writer
Page 2: Compiling and Debugging
Page 3: SmartContentSource Plugins

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
1.9 out of 5

91 people have rated this article.

Instantly Search Terabytes Of Text
“Lightning Fast”
– Redmond Mag
“Covers all data
sources” – eWeek
25+ fielded & full-text search options
dtSearch’s own document filters highlight hits in popular file types
Web Spider supports static & dynamic data
APIs for .NET, Java, C++, SQL, etc.
Win / Linux (64-bit & 32-bit)
www.dtSearch.com
 

      LearnNow

 

DevTeach