How to combine URIs

前端 未结 5 1443
情话喂你
情话喂你 2020-12-15 17:54

I have two Uri objects passed into some code, one is a directory and the other is a filename (or a relative path)

var a = new Uri(\"file:///C:/Some/Dirs\");
         


        
5条回答
  •  暖寄归人
    2020-12-15 18:35

    You can try this extension method! Works always! ;-)

     public static class StringExtension
        {
            public static string UriCombine(this string str, string param)
            {
                if (!str.EndsWith("/"))
                {
                    str = str + "/";
                }
                var uri = new Uri(str);
                return new Uri(uri, param).AbsoluteUri;
            }
        }
    

    Angelo, Alessandro

提交回复
热议问题