Combine base Path and relative Path
//
// Pauthor - An authoring library for Pivot collections
// http://pauthor.codeplex.com
//
// This source code is released under the Microsoft Code Sharing License.
// For full details, see: http://pauthor.codeplex.com/license
//
using System;
using System.IO;
using System.Net;
public static class UriUtility
{
public static String Combine(String basePath, String relativePath)
{
Uri baseUri = new Uri(UriUtility.ExpandUri(basePath), UriKind.Absolute);
Uri relativeUri = new Uri(relativePath, UriKind.RelativeOrAbsolute);
String result = baseUri.IsAbsoluteUri ? baseUri.GetLeftPart(UriPartial.Query) : baseUri.ToString();
result += result.EndsWith("/") ? "" : "/";
result += relativeUri.IsAbsoluteUri ? relativeUri.PathAndQuery : relativeUri.ToString();
return UriUtility.ExpandUri(result);
}
public static String ExpandUri(String path)
{
Uri uri = new Uri(path, UriKind.RelativeOrAbsolute);
if (uri.IsAbsoluteUri)
{
if (uri.IsFile) return uri.LocalPath;
return uri.AbsoluteUri;
}
if (File.Exists(path) || Directory.Exists(path)) return Path.GetFullPath(path);
return path;
}
}
Related examples in the same category