从URI相对路径删除20% [英] Removing %20 from URI Relative Path

查看:134
本文介绍了从URI相对路径删除20%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成1目录到另一个相对路径。如果OutputDirectoryName属性是含有空格的目录中,空间使用%20进行编码,而不是一个空间。我创建一个Windows文件夹中的相对路径,所以我必须用空格有我relatiave路径。有没有指定URI是如何编码的干净的方式?我知道我可以做一个stirng上relativePath.ToString()代替,但我想知道如果有一个更好的实施。
感谢。

 公共字符串GetOutputDirectoryAsRelativePath(字符串baseDirectory)
{
乌里基本URI =新乌里(baseDirectory);
乌里destinationUri =新的URI(OutputDirectoryName);
乌里relativePath = baseUri.MakeRelativeUri(destinationUri);
返回relativePath.ToString();
}


解决方案

使用Uri.UnescapeDataString <? / p>

的http:// MSDN。 microsoft.com/en-us/library/system.uri.unescapedatastring.aspx


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();
}

解决方案

Use Uri.UnescapeDataString?

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

这篇关于从URI相对路径删除20%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆