How to create a method to fully utilize Uri.TryCreate? (or: combining multi-paths in a URL) -
i looking @ thread: path.combine urls? , thought maybe create path.combine. wrote:
private string combineurlparts(params string[] urlparts) { var myurl = new uri(urlparts[0]); (int x = 1; x < urlparts.length; x++) { if (!uri.trycreate(myurl, urlparts[x], out myurl)) { // log failure } } return myurl.tostring(); } the idea being list baseurl ("http://someurl.com/"), path ("/company/5/"), , part ("/financials/index.aspx") , have magically combined.
this method works. first time thru loop, combines base url , first path fine. 2nd time thru loop, uri.trycreate overwrites path second part yielding:
http://someurl.com/financials/index.aspx
instead of expecting:
http://someurl.com/company/5/financials/index.aspx
any ideas what's going on here?
i think passing same uri trycreate causing problem. try this:
uri t; if (!uri.trycreate(myurl, urlparts[x], out t)) { // log failure } myurl = t;
Comments
Post a Comment