views:

538

answers:

3

I need to move .NET code to the Compact Framework. That code uses HttpUtility.UrlEncode to encode query parameters, but System.Web isn't available on CF. What can I use instead?

A: 

You can look at bundling mono's implementation (optionally simplified). I don't know how many of the dependencies you'd have to bring in, though. It may or may not be feasible.

Matthew Flaschen
A: 

You probably will have to roll your own, or even better, cheat. Using reflector you will quickly see that there are a number of overloaded methods for UrlEncode, calling the version that just expects the string paramater eventually ends up converting the string to an array of bytes and calling an internal method.

Edit: Code snippet removed in case of copyright violation...

Tim Jarvis
Tim, including decompiled copywrited software on the web seems like a license violation to me.
Andrew Arnott
Andrew, well...MS did release the FCL source with VS2008. However, even so, you are probably correct. Just releasing it with a commercial product does not automatically give me rights to post it I guess. I'll edit the answer just in case. (a brain fart to post it in the first place)
Tim Jarvis
+6  A: 

Use Uri.EscapeDataString. It's nearly equivalent, and probably better anyway, and is included in NetCF.

More info on their differences.

Andrew Arnott