HtmlEncode and HtmlDecode on Client Side?

M

Mahmoud Al-Qudsi

I have a client-server program, that sends and receives information to
our ASP.NET server via a custom XML-over-HTTP protocol.

On the server-side, I am successfully using Server.HtmlEncode() and
Server.HtmlDecode() to get the data XML-ready and extract it from XML
documents.

My problem is on the (C#) client's side. Is there any way to access
HttpServerUtility.HtmlDecode/HtmlEncode without actually having a
server defined?

The entire program is done, I've completed the entire communication
layer without having to use MS' server class, and I don't want to
define a server here just to decode/encode a string.

I can write my own function to search for an array of encoded strings
and replace them with the opposite (or vice versa), but seems like
such a waste when I have HtmlEncode and HtmlDecode right there in the
framework.

Any ideas?
 
J

Jon Skeet [C# MVP]

I have a client-server program, that sends and receives information to
our ASP.NET server via a custom XML-over-HTTP protocol.

On the server-side, I am successfully using Server.HtmlEncode() and
Server.HtmlDecode() to get the data XML-ready and extract it from XML
documents.

My problem is on the (C#) client's side. Is there any way to access
HttpServerUtility.HtmlDecode/HtmlEncode without actually having a
server defined?

Well, you can use HttpUtility.HtmlEncode and HttpUtility.HtmlDecode -
they're just static methods. Add a reference to System.Web.dll and
you'll be fine. The calls in HttpServerUtility just call HttpUtility
anyway.

Jon
 
M

Mahmoud Al-Qudsi

Well, you can use HttpUtility.HtmlEncode and HttpUtility.HtmlDecode -
they're just static methods. Add a reference to System.Web.dll and
you'll be fine. The calls in HttpServerUtility just call HttpUtility
anyway.

Jon

Thanks Jon, that did the trick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top