Sunday, November 2, 2008

How to paste source code from Visual Studio into a blog ?

Yes, it's true. This is my first blog post on Blogger :) But if You think it's yet another dummy post, I'll surprise You. In this post, I'm going to share single thought about pasting C# source code directly from Visual Studio 2008 as it is my primary IDE. Let's begin, shall we ? ;]

OK. So U want to share code on a blog... This is actually typical case. Of course you want your code to have proper indentation, and probably syntax coloring. There's excellent piece of a free software that can help U with this - CopySourceAsHtml (CSAH) plugin for VS 2008. U can find it here. It's usage is as simple as selecting desired code, hitting right mouse click and selecting Copy As HTML... And this is how a typical C# hello world application looks like using formatting from this tool:

   20 /// 
   21     /// Some remarks :)
   22     /// 
   23     public class SomeClass
   24     {
   25         public const string MyString = "I'm a constant!";
   27         private static void Main(string[] args)
   28         {
   29             Console.WriteLine(MyString);
   30         }
   31     }

There's a one problem, however. This tool does not work with XAML or more generally with any XML code at all! Hope support will be added ASAP.


1 comment:

Marcin Budny said...

You can also use Windows Live Writer + Paste from Visual Studio plugin