【发布时间】:2011-02-07 19:17:28
【问题描述】:
我正在寻找一种将相对基本 Uri 与另一个相对路径结合起来的干净方法。我尝试了以下方法,但 Uri(Uri, string) 和 UriBuilder(Uri) 需要绝对 Uris(抛出 InvalidOperationException:相对 URI 不支持此操作)。
// 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;
我不想做任何丑陋的字符串操作来确保基本路径以斜杠等结尾。
【问题讨论】: