Xerratus
Happily stressed out, since 1974
Thursday, August 17, 2006
<< Find any control on the calling page from within a custom user control
Wireless NAS solution that you cannot buy! >>
Code-to-Html Color Formatter
Well it's about time!
Being a technical blogger, I occasionally like to post code snippets for code that I find useful or helpful for a myriad of things. The part I hate though is copying my code, which is nicely formatted in
Visual Studio 2005
, to
FreeTextBox
, which is the rich text editor for my blog. Yes, there are some nice
sites
that allow you to copy and paste in your code that generate html for you but going back and forth is sometimes a hassle. Also, I have my colors set up a tad bit different than some of the code-to-html generators so the conversion is never like I have it set up. There was always my trusty fall back; paste the selection into
Microsoft Word
then copy it again and THEN paste it into FreeTextBox. This worked but there was one very annoying problem; it wrapped each line with
<
p
></
p
>
tags. Because of this, the code always looked double-spaced. To manually go in and remove was a pain for larger chunks of code.
This is what I need/want?
The ability to select the code snippet I want right in visual studio.
Copy it.
Paste it straight into my blog rich textbox WITH the same colors that visual studio has.
After a little searching yesterday, I found EXACTLY what I was looking for; A
macro
written by Jeff Atwood (
www.codinghorror.com/blog
). This allows me to do what I need and I can present my code in a matter of minutes now, formatted just like I like it. Small, simple and complete... perfect. For those of you who need it, I implore you to try it.
Here's a quick snippet to demonstrate:
public
static
Control
FindControlByID(
ControlCollection
controls,
string
id)
{
Control
found =
null
;
foreach
(
Control
control
in
controls)
{
if
(control.HasControls())
{
found = FindControlByID(control.Controls, id);
if
(found !=
null
)
{
break
;
}
}
if
(control.ID == id)
{
found = control;
break
;
}
}
return
found;
}
Ahhhhhh, that's nice.
Thursday, August 17, 2006 @ 08:09 AM (-07:00) Pacific Daylight Time
Comments (0)
tags:
Programming
admin: Edit | Remove
Name
E-mail
Home page
Remember Me
Comment (Some html is allowed:
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u
) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.
Enter the code shown (prevents robots):
Live Comment Preview
Site Navigation
About Me
Calendar
Disclaimer
Site Search
Sponsored Links
Calendar
<
November 2008
>
Sun
Mon
Tue
Wed
Thu
Fri
Sat
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Monthly Archives
August, 2008 (1)
July, 2008 (1)
March, 2008 (2)
January, 2008 (3)
December, 2007 (3)
October, 2007 (1)
September, 2007 (1)
August, 2007 (5)
July, 2007 (5)
June, 2007 (3)
April, 2007 (5)
February, 2007 (2)
January, 2007 (2)
December, 2006 (9)
November, 2006 (15)
October, 2006 (19)
September, 2006 (3)
August, 2006 (5)
July, 2006 (4)
June, 2006 (6)
May, 2006 (12)
April, 2006 (20)
March, 2006 (11)
February, 2006 (14)
January, 2006 (14)
December, 2005 (23)
November, 2005 (23)
October, 2005 (42)
September, 2005 (4)
Categories
Alert (14)
Community Server (2)
Daily Quote (1)
Did you know (7)
Dumb Searches (1)
Dumbass (15)
General (133)
Haiku (6)
Holiday (5)
Movie quote (8)
Paladin (4)
Paris (1)
Parody (1)
Photo (24)
Political (2)
Priceless (7)
Programming (35)
Pytheus (2)
Rant (23)
Screen capture (15)
SQL (3)
Technical (39)
Video (4)
Vista (8)
Visual Studio 2005 (2)
Wifey (33)
XP (1)
Feeds
RSS
Atom
Good Reading
Code Better
Coding Horror
Computer Zen
Daily WTF
Days Bush Has Left
Dooce
Fargg
Me-Nikk
Post Secret
Rory Blythe
TechCrunch
Sign In