'How to correctly paste HTML into C# code with Visual Studio or Resharper (or any other tool!)?

Is there any way to make a "safe" paste into Visual Studio (C#) of HTML code? If I try to paste something like

<div class="user-info"><div class="user-action-time">answered <span title="2010-09-16 02:23:16Z" class="relativetime">21 mins ago</span>

into my code, C# will cry. Using the @ operator doesn't help us, either.

Is it possible to make a special paste in Visual Studio (2010) or Resharper?

Thanks



Solution 1:[1]

You can use SmartPaster Extention.

After install Right click -> Paste As... -> Paste as @String

Download links

Solution 2:[2]

Use @, select pasted text and replace " with "" in the selection. That's what I do when I paste text containing quotes.

Solution 3:[3]

So none of the above worked for me! Copying a large multi-line code snippet from a web page and pasting into VS2010 always reulted in a single line with no linefeeds. The quickest work-around was to paste the HTML into MS Word and then copy this and paste it into VS2010. HTH, Matt

Solution 4:[4]

Have you looked at this?

http://www.clipboardfusion.com/

I don't have any personal experience, but it seems like a flexible way to perform any kind of manipulation to the clipboard you like (since you can define transforms in C#) and it's free. As noted by Alex, just doubling up on double-quotes should be fine, providing you preface the string with an '@' and this won't even need any code - just a simple string search / replace.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vasilis Plavos
Solution 2 Alex Paven
Solution 3 MattPil29
Solution 4 Bob Sammers