I need to encode a url in my WP7 application. The class im using dosent seem to encode # (to %23). Any ideas what im doing wrong?
string foo = InkBunnyUrls.Login + "&username=" + txtUsername.Text + "&password=" + txtPassword.Password;
//foo = https://inkbunny.net/api_login.php?output_mode=xml&username=test&password=foobar#1
string url = System.Net.HttpUtility.HtmlEncode(foo);
// url = https://inkbunny.net/api_login.php?output_mode=xml&username=test&password=foobar#1
Edit: I tried UrlEncode and that dosent work (see below). Reading the msdn doc it wont escape # . I cant use the system.web class as it isnt in WP7
string foo = InkBunnyUrls.Login + "&username=" + txtUsername.Text + "&password=" + txtPassword.Password;
//foo = https://inkbunny.net/api_login.php?output_mode=xml&username=test&password=foobar#1
string url = Uri.EscapeUriString(foo);
// https://inkbunny.net/api_login.php?output_mode=xml&username=test&password=foobar#1
The
#symbol doesn’t need to be HTML-encoded.If you’re expecting the result to be
%23then you should look atUrlEncodeinstead:EDIT…
Do the WP7 libs support
EscapeDataString?