Queens Dev
Some more ASP.NET

Convert Code Syntax Highlighting to HTML for Posting Online

September 18, 2008 at 5:11 AM by bjsetegn

I come across many websites and blogs these days that still don't format their code well when posting it online.  Whenever I see a site with poorly styled code I wonder how good of a programmer they actually are and how little effort they put into their site.  For those of us with Visual Studio this task has been made pretty simple thanks to a tool called CopySourceAsHtml.  This simple tool integrates with Visual Studio to allow you to copy out its syntax highlighting to html exactly as you see it.  Since Visual Studio adds syntax highlighting to many common file types it makes its easy to generate html from almost any of your source code.

I found this tool to be the easiest to use because it doesn't require you to install or change anything on your website.  It also creates html that displays well in most browsers.  Some browsers like Internet Explorer will ignore tags like <pre> which is used to mark text as preformatted.  CopySourceAsHtml doesn't use <pre> tags it mostly uses <p> paragraphs and <span> spans.  It also lets you add specific styling to certain sections making it more dynamic.  A link to the author's website for more details and a download are below.  Also included is a link to convert the add-on to run in Visual Studio 2008.

Links

http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/- Copy Source As HTML

http://developers.de/blogs/andreas_erben/archive/2007/08/01/using-copysourceashtml-with-visual-studio-2008-beta-2.aspx- Visual Studio 2008 Fix

Open Source Icon Sets

July 2, 2008 at 5:08 AM by bjsetegn

I am not an artist in any way, shape, or form.  Pretty much all of the graphics and most of the styles you see here are from outside sources.  But I always like to give credit where credit is due.  For someone who isn't an expert at Photoshop these sets can really save time.

Crystal

A few of the recent images l have added here are from an open source icon set called Crystal.    It is available under the GNU General Public License and was created by a Brazilian by the name of Everaldo Coelho.  It is a pretty extensive and high quality set which is very appropriate for Web 2.0 sites.

Silk

I also want to mention the Silk icon set.  I have used those images on projects in the past .  While not as high quality as the Crystal set these images have proven to be very usefull.

 

VBScript to Change AutoText in Word 2003 Normal.dot

March 20, 2008 at 1:17 AM by bjsetegn

My client recently changed there name for branding reasons, making it more concise.  They have around 100 employees using Word with an Autotext (auto complete) entry for their old company name.  For anyone who doesn't already know what the Autotext feature is in Word it is a special feature that will complete a phrase for you after you type the first couple of letters for it.  This actual text for the Autotext is stored in the Normal.Dot file located deep within your file systems  which is the default Word template.  This template is loaded every time you open a new document.  Outlook also uses Word as its editor and thus uses the Normal.dot.  

Anyway, they wanted to change the Autotext entry for their company name on all 100 computers.  This would have been quite a hassle for each user to do themselves or taken a lot of time for one person to run around to each computer and change it.  So they had me write a script that would change the entry and could be set to run the next time the user logged in.  At first I tried to edit the Normal.dot file manually through a filestream but I ran into problems when writing the changes back.  Special characters and other items in the file header were either erased or changed and the file would be corrupted.  So I reached out for some help and an IT guy sent me a link to some code that looked a lot like what I have below (I can't find the link or I would post it, only half of what's below I will claim as my own work, the easy half).  I modified it to work for my situation and added some error checking in case it was run more than once and the old record wasn't found.  It worked pretty well and for once I was assured I had saved the client some money.  Oh how powerful vbscript can be.

To run the code save the text below to a text file such as RenameAutotext.vbs.  Then from the command prompt run: cscript RenameAutotext.vbs.  Run using cscript not wscript because if run using wscript will send the Echo command to the program running, Word, instead of writing it to the command line.  This script is also test to work only for Windows XP and Microsoft Word 2003.  Word 2007 uses a different type of template file so and this script will need to be modified to work with that.

There may be some extraneous parts that aren't 100% necessary below but with vbscript I am happy when I get it to do exactly what I want and leave it at that.  If anyone has some suggestions for improvement leave a comment. 

The Code: 

    'Rename an

    'Get Application Data Path

    Set oShell = CreateObject("WScript.Shell")

    appdata = oShell.ExpandEnvironmentStrings("%APPDATA%")

 

    Set objWord = CreateObject("Word.Application")

    objWord.Visible = True

 

    Set objDoc = objWord.Documents.Open(appdata & "\Microsoft\Templates\Normal.dot", False)

 

    'Add new autotext entries

    Set objTxtEntry = objWord.NormalTemplate.AutoTextEntries.Add("New Company Name", objWord.Selection.Range)

    objWord.NormalTemplate.AutoTextEntries("New Company Name").Value = "New Company Name"

 

    'Enable error handling

    On Error Resume Next

    'Delete old autotext entries

    objWord.NormalTemplate.AutoTextEntries("Old Company Name").Delete

 

    If Err.Number <> 0 Then

        WScript.Echo "No Old Company Name record found, new entry inserted."

    Else

        WScript.Echo "Completed Successfully."

    End If

 

    'Print all autotext entires to make sure it was changed properly

    'Wscript.Echo

    Dim i

    For Each i In objWord.NormalTemplate.AutoTextEntries

       Wscript.Echo i.Name

    Next

 

    objWord.Quit