Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing %20 from URI Relative Path

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();
}
like image 573
Stealth Rabbi Avatar asked Apr 18 '11 17:04

Stealth Rabbi


3 Answers

You can use

Uri.UnescapeDataString

http://msdn.microsoft.com/en-us/library/system.uri.unescapedatastring.aspx

like image 65
darth happyface Avatar answered Nov 17 '22 02:11

darth happyface


string sRelativeFilePath = Uri.UnescapeDataString(new Uri(sAbsolutePath + "\\", false).MakeRelative(new Uri(filename)));
like image 23
Nisha Avatar answered Nov 17 '22 01:11

Nisha


Use HttpServerUtility.UrlDecode Method (String)

like image 20
Tomas Voracek Avatar answered Nov 17 '22 02:11

Tomas Voracek