views:

850

answers:

4

Is there a way to copy code from visual studio (C#) and paste it into OneNote, without losing the formatting?

I was able to do this, but only if I copy from VS, paste to Word, copy from Word, and then paste to OneNote.

+4  A: 

You have hit the nail on the head on the process. The application that you are pasting to must be able to accept the code with the formatting properly. MS Word is one of the few that handles this properly, therefore, going from VS -> Word -> OneNote will work. But VS -> OneNote doesn't work.

Mitchel Sellers
another app that will work are a message in outlook (best with it set to Rich Text Mode)
ShuggyCoUk
@ShuggyCoUk - Yes, that is correct, but I believe that it only works if you have Word as the editor.
Mitchel Sellers
I tried the trick, but it didn't work fully for me. Colors were correct but the indention was lost.
Karsten
+1  A: 

There is an add-in for Microsoft Visual Studio that allows you to copy source code, syntax highlighting, and line numbers as HTML.

With this add-in, you can copy from VS and paste HTML directly to your target.

Check it out here: CopySourceAsHtml

Lawrence P. Kelley
A: 

CopySourceAsHTML does not work with Onenote

Ealbert
+4  A: 

There is fortunately a solution for Visual Studio 2010! Install the Visual Studio 2010 Pro Power Tools extension and copy/paste to OneNote retains syntax highlighting. Made me a happy man;)

Jan Roelof

Jan Roelof
Exactly what I was looking for.. thanks Jan
satyajit