The method above is still valid when encoding HTML tags, but fails short when encoding quotations and ampersands.
We need to encode the ampersands (the ‘). This will produce a correct output:
The \ will escape the ‘ signs.
For us who does not have the possibility to use .NET 4.0, the function is pretty easy to develop. And why not pair it with the System.Uri.EscapeDataString() so you get a complete clean string encoding.
This Extension Method will escape the data and all quotes in one go:
To use the function you can do the following:
Now you will never have any problems with HTML tags, quotes, double quotes, ampersands or other special signs.