Skip to main content

CopySourceAsHTML for Visual Studio 2008 : Tips & Tricks

For a tech blogger who wants to show off a lot of codes , the gruesome process of Ctrl+C and Ctrl+V may not be of big help . Why? Because your blog may not be WYSIWYG and the pasted code just mess up your post . Then came CopySourceAsHTML for Visual Studio developers . Sleek and handy , just copy the code from your editor and paste it to your blog as HTML with all the CSS embedded in it to copy even the color schemes of the editor . Cool right? Well, the installer works only for Visual Studio 2005 !!!! And if your a developer working now on Visual Studio 2008 ( obviously I am ) , you dont have the capability to do that easily .

Just an hour ago I stumble on a site that allows you to download a CopySourceAsHTML compatible for Visual Studio 2008 . The bad news is that its not an installer but a zipped file containing 3 files that should be manually added to VS2008 . Here are the steps to make it run together with some test scenarios I did.

1. Download the Zip File on this SITE
2. Unzipped the file into [VS2008 Folder in my documents]\AddIns . If the folder does not exist , create it .
3. Open your Visual Studio 2008 then go to Tools|Options. On the Add in/Macro Security , add the path of the Add In folder you created in step #2 . Restart VS2008 .
4. After restart , double check if the CSAH is already added as an add-in by going to Tools | Add In Manager .
5. If you did all the steps correctly , the Copy As HTML item is already added in your context menu .

Testing Results :
Here are some things worth mentioning about CSAH for VS2008. Assuming we have the following code to be pasted in this blog .

1. If we copy lines 6 to 14 using the CSAH , we would not have any problem as shown below :
    6 namespace MVP
    7 {
    8     public interface ILogin
    9     {
   10         string UserID { get; set; }
   11         string Password { get; set; }
   12         bool RememberMe { get; set; }
   13     }
   14 }

2. But if copy only lines 8 to 13 , you would see slight problem at the first line as evident below:
    8 public interface ILogin
    9     {
   10         string UserID { get; set; }
   11         string Password { get; set; }
   12         bool RememberMe { get; set; }
   13     }

It is not a big issue but kinda ugly . You can fix this by adding spaces in the first line of the HTML generated code or you could probably start copying at line 7 as shown below :
    8     public interface ILogin
    9     {
   10         string UserID { get; set; }
   11         string Password { get; set; }
   12         bool RememberMe { get; set; }
   13     }

3. One more thing for blogspot users , make sure that the "strip line break" option is checked to avoid double spaces in your post.


Anonymous said…
There is no "Add in/Macro Security" after selecting Tools/Options. What did you do to get that?
Marvin said…

the Add In/Macro Security is found under the Environment tree , just below the General item.

Thank you for visiting my blog.


Popular posts from this blog

Hiding Unwanted Python Folders and Files in Visual Studio Code

Visual Studio Code is a universal editor and pretty good at it. However, the explorer view maybe cluttered with the automatically generated folders and files confusing developers. Python is no different. Below are example files and folders generated by Python.

The __pycache__ folder and *.pyc files  are totally unnecessary to the developer. To hide these files from the explorer view, we need to edit the settings.json for VSCode. Add the folder and the files as shown below:
Copy and paste the lines below :


renaming default namespaces for VSTO projects in VS2008

So here is the scenario , you are starting a VSTO project and decided that your default namespace is ExcelAddInTesterApp . You created the project and started coding the project. After several days , your boss called and said "hey marvin , make use of this namespace OurCompany.ExcelAddInTesterApp , we have to add our company name to it got it?" . You get back to your machine thinking its just a simple property just like any project you've been working on. So you right clicked the VSTO project and hit properties . Boom! What the F@#$? The default namespace textbox is disabled!!!!

I've been through this and I googled for ways to do it and ended up with a blog from a Microsoft MVP telling me it can't be done because it is disabled. Then I thought of Refactoring, the beauty and grandeur of the renaming process. I selected the namespace and hit the refactor menu hoping that this would solve the problem . Unfortunately , it did not rather it displayed the message box …

Automatic Properties and Object Initializers in .Net 3.5

With the release of .Net 3.5 alongside with Visual Studio 2008 , new enhancements was again introduced . Some maybe well pronounced such as the inclusion of WCF, WPF , LINQ in .Net 3.0 and some just came unnoticed. If you have been accustomed of using a particular method or technique in implementing a certain code in .Net 2.0 , because of backward compatibility , you may not even notice that there are new ways of implementing it in .Net 3.5.

Here are two new concepts in .Net 3.5 that a developer may not notice ( at least in my opinion ) : Automatic Properties and Object Initializers . To illustrate these two , I am going to present the pre-.Net 3.5 way (.Net 2.0) and the .Net 3.5 way in creating a simple class with simple properties.

Automatic Properties

Creating a class can be tedious , especially when working with a list of properties , . One way to get around having to type the code for a private field and its public property getter and setter is to use a refactoring tool. However, …