public static Uri GetRelativeUri(Uri sourcePartUri, Uri targetPartUri) { Check.SourcePartUri(sourcePartUri); Check.TargetPartUri(targetPartUri); Uri uri = new Uri("http://fake.com"); Uri a = new Uri(uri, sourcePartUri.OriginalString); Uri b = new Uri(uri, targetPartUri.OriginalString); return(a.MakeRelativeUri(b)); }
public static Uri ResolvePartUri(Uri sourcePartUri, Uri targetUri) { Check.SourcePartUri(sourcePartUri); Check.TargetUri(targetUri); Check.PartUriIsValid(sourcePartUri); if (targetUri.IsAbsoluteUri) { throw new ArgumentException("targetUri", "Absolute URIs are not supported"); } // Need to trim first 7 chars as they are: "file://" return(new Uri(new Uri(sourcePartUri, targetUri).OriginalString.Substring(7), UriKind.Relative)); }
public static Uri ResolvePartUri(Uri sourcePartUri, Uri targetUri) { Check.SourcePartUri(sourcePartUri); Check.TargetUri(targetUri); Check.PartUriIsValid(sourcePartUri); // commented out because on Android they are absolute file:/// // if (targetUri.IsAbsoluteUri) // throw new ArgumentException("targetUri", "Absolute URIs are not supported"); Uri uri = new Uri("http://fake.com"); uri = new Uri(uri, sourcePartUri); uri = new Uri(uri, targetUri); // Trim out 'http://fake.com' return(new Uri(uri.OriginalString.Substring(15), UriKind.Relative)); }