Use EscapeUriString instead of UrlEncode for Silverlight

by brad 10. August 2010 13:26

If your first experience escaping a URL in Silverlight is anything like mine, the first tool you will reach for might be HttpUtility.UrlEncode.

HttpUtility.UrlEncode(“http://www.google.com/m8/feeds/contacts/example@gmail.com/full”)

But wait! HttpUtility is in System.Web, which is definitely NOT part of the standard Silverlight reference pack.  So the question now is “Do I want to include System.Web in my Silverlight application for one line of code?”  And the answer is “Nope”.

Instead, you can use EscapeUriString which comes in the System assembly.

Uri.EscapeUriString(“http://www.google.com/m8/feeds/contacts/example@gmail.com/full”)

Same result, without adding a unnecessary assembly to your Silverlight application.

Tags:

Silverlight

Comments

Comments are closed

About Brad

Brad Tutterow lives in Illinois and works in Missouri. He has 12 years of experience developing web sites and Windows applications using a variety of technologies and is most excited currently about Silverlight, Windows Phone 7, Halo Reach, and Visual Studio 2010.