c# - Cascade a url string -
coming this question, i'm looking way cascade url path.combine
file system including path-parameter.
my input following 3 parameters:
string host = "test.com"; //also possilbe: "test.com/" string path = "/foo/"; //also possilbe: "foo", "/", "","/foo","foo/" string file = "test.temp"; //also possilbe: "/test.temp"
the expected result is
http://test.com/foo/test.temp
this approach best find does'n work cases:
uri myuri = new uri(new uri("http://" + host +"/"+ path), file);
you try using uri.trycreate()
:
uri uri; bool success = uri.trycreate(new uri("http://" + host), path.trim('/') + "/" + file.trim('/'), out uri);
this return false
if url somehow in incorrect format. however, if sure format correct, can use uri
constructor:
var uri = new uri(new uri("http://" + host), path.trim('/') + "/" + file.trim('/'));
Comments
Post a Comment