我正在寻找一种干净的方式来将相对基础Uri与另一个相对路径结合起来。我试过以下,但Uri(Uri, string)
和UriBuilder(Uri)
要求绝对Uris(抛出InvalidOperationException:此操作不支持相对URI)。结合相对baseUri与相对路径
// where Settings.Default.ImagesPath is "~/path/to/images"
// attempt 1
_imagePath = new Uri(Settings.Default.ImagesPath, image);
// attempt 2
UriBuilder uriBuilder = new UriBuilder(Settings.Default.ImagesPath);
uriBuilder.Path += image;
_imagePath = uriBuilder.Uri;
我不想做任何丑陋的字符串操作,以确保基本路径以斜线结束,等
这与我的尝试2示例相同。它引发“InvalidOperationException:此操作不支持相对URI” – jrummell 2011-02-07 19:28:03