Tuesday, June 9, 2009

Copy code as HTML on Visual Studio, easy way to copy code on blogspot

I just notice that blogspot has limited capability on doing blog for programming code. Copy and paste from word also won't work properly as blogspot will not tolerate some whitespace character generated by Word. Luckily, on the net I found something that can address this issue.

Guy Burstein, provide a link to Microsoft Visual Studio AddIns that will allow us to copy any code that we highlight within Visual Studio and paste it automatically as HTML code. This will be helpfull lot on writing a code blog on blogspot, eventough we have to use manual HTML code still and it's exclusively to Visual Studio :)

So, here are steps to doing this:

1. Obtain AddIns here

2. Extract it to your Visual Studio AddIns folder, it's should be under MyDocuments\Visual Studio 2008\Addins, if you couldn't find AddIns folder, then create new one

3. Open Visual Studio, click on Tools -> AddIn Manager


4. AddIn manager dialog will be opened, select to activate "Copy as HTML" AddIn


5. Now, you can select any code and when do right click, "Copy as HTML" will be shown

Below is the result :)


  195 Public ReadOnly Property Email() As String


  196             Get


  197                 Dim daUser As New UserTableAdapter


  198                 Dim ret As String = ""


  199                 Dim users() As String = {}


  200                 Dim i As Integer = 0


  201 


  202                 For Each row As SecurityApprovalRow In Me.Rows


  203                     If Array.IndexOf(users, row.UserId) < 0 Then


  204                         Array.Resize(users, i + 1)


  205                         users(i) = row.User.Email


  206                         i += 1


  207                     End If


  208                 Next


  209                 Return IIf(users.Length = 0, "", String.Join(";", users))


  210             End Get


  211         End Property





Nice isn't ? Try it, code with smile :)