Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

System.Uri.UserEscaped

5 views
Skip to first unread message

Sathyaish

unread,
May 5, 2006, 5:13:12 AM5/5/06
to
I need help understanding this property. It totally escapes me, pun
intended.

The documentation says:

<DOCUMENTATION>
Summary
Gets a Boolean value that indicates whether the URI information used to
construct the current instance was escaped before the current instance
was created.

Property Value
true if the dontEscape parameter of the constructor for the current
instance was set to true ; otherwise, false.
</DOCUMENTATION>

I understood it as, if the Uri specified as the argument in the
constructor of this class is already URLEncoded, then this property is
set to True, and otherwise to false. So, I tried this code:


<CODE>
try
{
u = new Uri("http%3A%2F%2Fwww%2Esathyaish%2Ecom");
}
catch(Exception e)
{
Console.WriteLine(e.Message);
return;
}

Console.WriteLine("\nUserEscaped: " + u.UserEscaped);
</CODE>


I also tried two other URLs given below (not URL Encoded this time):

1. http://www.yahoo.com
2. http://discuss.joelonsoftware.com/?joel

The property always returns False. What's the deal?

Kalpesh

unread,
May 5, 2006, 5:35:09 AM5/5/06
to

Look at the overloaded constructor & the following code

// here the uri is already encoded (using %20), hence dont ask uri to
put escape chars
// if you dont pass true, it is false by default. hence userescaped
will return false
Uri u2 = new Uri("http://www.somesite.com/some%20page.htm", true);
Console.WriteLine(u2.UserEscaped);
Console.WriteLine(u2.ToString());

HTH
Kalpesh

Sathyaish

unread,
May 5, 2006, 5:58:03 AM5/5/06
to
ah! so you gotta tell the Uri object yourself that you've escaped the
characters. I was assuming it'd be intelligent enough to figure that
out.

0 new messages