I am generating a relative path from 1 directory to another. If the OutputDirectoryName property is a directory containing spaces, the spaces are encoded using %20, rather than a space. I am creating a relative path to a windows folder, so I must have my relatiave path using spaces. Is there a clean way to specify how the URI is encoded? I know I could do a stirng replace on the relativePath.ToString(), but am wondering if there's a better implementation. Thanks.
public string GetOutputDirectoryAsRelativePath(string baseDirectory)
{
Uri baseUri = new Uri(baseDirectory);
Uri destinationUri = new Uri(OutputDirectoryName);
Uri relativePath = baseUri.MakeRelativeUri(destinationUri);
return relativePath.ToString();
}
You can use
Uri.UnescapeDataString
http://msdn.microsoft.com/en-us/library/system.uri.unescapedatastring.aspx
string sRelativeFilePath = Uri.UnescapeDataString(new Uri(sAbsolutePath + "\\", false).MakeRelative(new Uri(filename)));
Use HttpServerUtility.UrlDecode Method (String)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With