Given an absolute URI/URL, I want to get a URI/URL which doesn\'t contain the leaf portion. For example: given http://foo.com/bar/baz.html, I should get http://foo.com/bar/.
This is the shortest I can come up with:
static string GetParentUriString(Uri uri) { return uri.AbsoluteUri.Remove(uri.AbsoluteUri.Length - uri.Segments.Last().Length); }
If you want to use the Last() method, you will have to include System.Linq.