/// <summary>
/// Get relative path for a given file path
/// </summary>
/// <param name="baseDirectory">Base directory</param>
/// <param name="filePath">A file path</param>
/// <returns>A relative path location</returns>
public static string GetRelativePath(string baseDirectory, string filePath)
{
if (String.IsNullOrEmpty(baseDirectory))
throw new ArgumentNullException("BaseDirectory");
if (String.IsNullOrEmpty(filePath))
throw new ArgumentNullException("FilePath");
if (!baseDirectory.EndsWith("\\"))
baseDirectory += "\\";
System.Uri uri1 = new Uri(filePath);
System.Uri uri2 = new Uri(baseDirectory);
Uri relativeUri = uri2.MakeRelativeUri(uri1);
return relativeUri.ToString();
}
No comments:
Post a Comment