Scott on Writing

Musings on technical writing...

Displaying Formatted Source Code in a Web Page

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.

posted on Friday, June 30, 2006 9:51 AM

Feedback

# re: Displaying Formatted Source Code in a Web Page 6/30/2006 12:00 PM Scott Mitchell

CORRECTION: You _can_ CopyHtmlAsHtml, it's just not available from the context menu. In short, in an ASP.NET page you need to highlight the text and then go up to the Edit menu...

# re: Displaying Formatted Source Code in a Web Page 6/30/2006 6:04 PM Jeff Atwood

Give my VS.NET HTML conversion macro a shot. I think it's easier than installing an .exe, and you get your choice of HTML or text HTML in the clipboard.

http://www.codinghorror.com/blog/archives/000429.html

It also has the advantage of working with any file type that VS.NET understands.

# re: Displaying Formatted Source Code in a Web Page 7/1/2006 11:03 AM Gail

will this work for VWD?

# A good JavaScript Syntax Higlighter 7/2/2006 7:48 PM Marcos Meli

I use a JavaScript class to highlight code examples:

http://www.dreamprojections.com/syntaxhighlighter

Is excellent because you only paste the code and don´t need to worry how it look, also has other options to show th eline or columns numbers, etc.

Some examples

http://filehelpers.sourceforge.net/example_easy.html
http://filehelpers.sourceforge.net/example_progress.html

Cheers
Marcos

# re: Displaying Formatted Source Code in a Web Page 7/4/2006 4:17 AM jokiz

i was surprised that you only knew the said addin which was featured in msdn mag months ago. good thing you blogged about it since i haven't seen jeff atwoord's macro version.

# Displaying Formatted Source Code in a Web Page 8/24/2006 7:13 PM Heybo Blog

# Download CopySourceAsHtml 8/25/2008 9:50 AM Scott on Writing

# Download CopySourceAsHtml 8/25/2008 9:55 AM ASPInsiders

CopySourceAsHtml (CSAH) is a free Visual Studio Add-In created by Colin Coller that turns Visual Studio

# Download CopySourceAsHtml 8/25/2008 10:20 AM BusinessRx Reading List

CopySourceAsHtml (CSAH) is a free Visual Studio Add-In created by Colin Coller that turns Visual Studio

# Download CopySourceAsHtml 8/25/2008 3:10 PM Readed By Wrocław NUG members

CopySourceAsHtml (CSAH) is a free Visual StudioAdd-In created by Colin Coller that turns Visual Studio

# re: Displaying Formatted Source Code in a Web Page 2/13/2009 11:12 PM Matt

Scott,

Know any way to copy .aspx source code to HTML and not just code-behind code??

I'm not a hard-core programmer but want to write some tutorials on the .aspx source code like page headers, meta-data tagging methods etc...

Thank you,
Matt

# re: Displaying Formatted Source Code in a Web Page 2/14/2009 11:35 AM Scott Mitchell

Matt, you can use CSAH for generating HTML for the declarative markup in the .aspx portion of an ASP.NET page, although it's not straightforward. When I select declarative markup I do NOT see the "Copy Source as Html" option in the context menu. However, after selecting the declarative markup I can go to the Edit menu and choose "Copy Source as Html".

This worked for me using CSAH 3.0 and Visual Studio 2008.

Thanks

Title:  
Name:  
Url:
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments   

My Links

Ads Via DevMavens

Archives

Post Categories

 

I am a Microsoft MVP for ASP.NET.
I am an ASPInsider.
<July 2009>
SMTWTFS
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

Comment Stats

DayTotal% of Total
Sunday 2046.9%
Monday 42314.3%
Tuesday 50116.9%
Wednesday 54518.4%
Thursday 57219.3%
Friday 53618.1%
Saturday 1856.2%
Total 2966100.0%

Hour1Total% of Total
12:00 AM 752.5%
1:00 AM 802.7%
2:00 AM 672.3%
3:00 AM 812.7%
4:00 AM 642.2%
5:00 AM 1234.1%
6:00 AM 1153.9%
7:00 AM 1755.9%
8:00 AM 1876.3%
9:00 AM 1565.3%
10:00 AM 1866.3%
11:00 AM 1926.5%
12:00 PM 1996.7%
1:00 PM 1846.2%
2:00 PM 1675.6%
3:00 PM 1344.5%
4:00 PM 1153.9%
5:00 PM 1063.6%
6:00 PM 993.3%
7:00 PM 1063.6%
8:00 PM 903.0%
9:00 PM 842.8%
10:00 PM 893.0%
11:00 PM 923.1%
Total 2966100.0%

Comments by Blog Entry Date/Time

Day Entry MadeAvg.Total
Sunday 4.91157
Monday 4.92379
Tuesday 4.21471
Wednesday 7.42668
Thursday 6.53666
Friday 5.17450
Saturday 4.73175
Total 5.522966

Hour1 Entry MadeAvg.Total
12:00 AM 5.2937
1:00 AM 1.002
5:00 AM 0.000
7:00 AM 4.0048
8:00 AM 4.29133
9:00 AM 6.04290
10:00 AM 5.83274
11:00 AM 4.36192
12:00 PM 6.44348
1:00 PM 3.14132
2:00 PM 5.04227
3:00 PM 7.97303
4:00 PM 3.8199
5:00 PM 6.00168
6:00 PM 4.56114
7:00 PM 8.95188
8:00 PM 8.58163
9:00 PM 5.00115
10:00 PM 6.31101
11:00 PM 4.5732
Total 5.522966

Learn More About Comment Stats
1 - All times GMT -8...


Blog Stats

Favorite Web Sites

My Books

My MSDN Articles