Displaying Formatted Source Code in a Web Page

Published 30 June 06 09:51 AM | Scott Mitchell

In my last blog entry you may have noticed that my code snippet looks rather spiffy. Here, let me show off just how spiffy my source code formatting is!

1 private ProductsTableAdapter _productsAdapter = null;

2 protected ProductsTableAdapter Adapter

3 {

4 get {

5 if (_productsAdapter == null)

6 _productsAdapter = new ProductsTableAdapter();

7

8 return _productsAdapter;

9 }

10 }

11

12 [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]

13 public Northwind.ProductsDataTable GetProducts()

14 {

15 return Adapter.GetProducts();

16 }

Whee, that was fun and easy. Easy because of a free Visual Studio plug-in (one for VS.NET, one for VS 2005) I found earlier in the week, Colin Coller's CopySourceAsHtml (CSAH). Just highlight source code in Visual Studio, right-click and choose Copy as Html. Colin's plug-in then converts the highlighted code into HTML that accurately reflects your Visual Studio's appearance settings. A quick and easy way to show your code on your blog or in online articles!

The only downside I see is that it appears that you can't CopyHtmlAsHtml. That is, when I highlight markup in an ASP.NET page, there's no Copy as Html option in the context menu.

Filed under:

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Archives

My Books

  • Teach Yourself ASP.NET 4 in 24 Hours
  • Teach Yourself ASP.NET 3.5 in 24 Hours
  • Teach Yourself ASP.NET 2.0 in 24 Hours
  • ASP.NET Data Web Controls Kick Start
  • ASP.NET: Tips, Tutorials, and Code
  • Designing Active Server Pages
  • Teach Yourself Active Server Pages 3.0 in 21 Days

I am a Microsoft MVP for ASP.NET.

I am an ASPInsider.