The past few blog posts that I have made had some code in them, and the formatting was lost. I am using Word 2007 for posting to my blog (like a good corporate citizen), but was just about to give up. The blog posts are really hard to read when you have unformatted code in them.
Today I heard about Colin Coller’s CopySourceAsHTML. It adds a context menu item so that when you right-click on source in Visual Studio 2005, it will copy the source as HTML. Then you can paste the source into Word 2007, and you get some semblance of code formatting.
You can control whether you get line numbers or not, override CSS, and a few other cool features. The only shortcoming that I see is that it doesn’t seem to support ASPX files yet. This tool is really impressive in that you can copy XML, C++, and J# just as easily as C# or VB.NET. Bravo, Colin!
Here are some results of copying from Visual Studio 2005 using CopySourceAsHTML and pasting into Word 2007.
<service behaviorConfiguration=“returnFaults“ name=“service2“>
<endpoint binding=“basicHttpBinding“ contract=“Iservice2“/>
<endpoint address=“mex“ binding=“mexHttpBinding“ contract=“IMetadataExchange“/>
<add name=“MyBehavior“ type=“WCFExtensions.MyBehaviorExtension, WCFExtensions, Version=188.8.131.52, Culture=neutral, PublicKeyToken=null“/>
<add name=“XmlSerialization.Compilation“ value=“1“ />
// RealEstate.cpp : main project file.
using namespace System;
int main(array<System::String ^> ^args)
* Summary description for Service1.
public class Service1 extends System.ServiceProcess.ServiceBase
* Required designer variable.
private System.ComponentModel.IContainer components;
// This call is required by the Windows.Forms Component Designer.
// TODO: Add any initialization after the InitComponent call
#region Windows Form Designer generated code
* Clean up any resources being used.
protected void Dispose(boolean disposing)
if (components != null)
* Required method for Designer support – do not modify
* the contents of this method with the code editor.
private void InitializeComponent()
components = new System.ComponentModel.Container();
* Set things in motion so your service can do its work.
protected void OnStart(String args)
// TODO: Add code here to start your service.
* Stop this service.
protected void OnStop()
// TODO: Add code here to perform any tear-down necessary to stop your service.