It'd be really nice to target my Windows Forms app to the .NET 3.5 SP1 client framework. But, right now I'm using the HttpUtility.HtmlDecode
and HttpUtility.UrlDecode
functions, and the MSDN documentation doesn't point to any alternatives inside of, say, System.Net or something.
So, short from reflectoring the source code and copying it into my assembly---which I don't think would be worth it---are there alternatives inside of the .NET 3.5 SP1 client framework that you know of, to replace this functionality? It seems a bit strange that they'd restrict these useful functions to server-only code.
I reverse engineered the Microsoft System.Net.WebUtility class from .NET 4.0 using Reflector (I think they'd be ok with it given the circumstances). So you could either use .NET 4.0 Client Framework (which now has this new class) or use the code here.
As long as you use a strong name on your assembly etc., you'll be safe enough. Here:
Found today from this here little site that HtmlEncode/Decode can be done using System.Net library in C# 4.0 Client Profile:
Edit: I re-read that the question applied for the 3.5 Client Framework but maybe this can be useful those who have updated 4.0..
Apparently google couldn't find it either, so they wrote there own api-compatible version:
Here's a workaround:
Compile Google's version as a library
Edit
your-project.cs
to include that namespaceRecompile using the library
From glancing at the source code, it appears that this is
.NET 2.0
-compatible.I just wrote my first hello world in csharp yesterday and I ran into this problem, so I hope this helps someone else.
I’d strongly not recommend rolling your own encoding. I’d use the Microsoft Anti-Cross Site Scripting Library which is very small (v1.5 is ~30kb) if HttpUtility.HtmlEncode isn’t available.
As for decoding, maybe you could use the decoding routine from Mono?
When addressing Windows Phone and the Desktop (Client profile!) world the fastest way I found is:
The odd thing for me was that the namespace is System.Net but the class name differs in the Windows Phone world ... (don't like to use System.Web/full profile when not really needed and the System.Web isn't supported on the Windows Phone platform anyway ...)
Two main ways :