例外:"不支持URI格式"

How*_*wie 85 .net c# .net-4.0

我有一个指向dir的绝对本地路径: "file:\\C:\\Users\\john\\documents\\visual studio 2010\\Projects\\proj"

但是当我试图将它扔进DirectoryInfo我的ctor时,我得到了"不支持URI格式"的例外.

我用Google搜索并查看了SO,但我只看到了远程路径的解决方案,而不是本地解决方案.我期待某种转换方法......

Mar*_*ell 180

string uriPath =
    "file:\\C:\\Users\\john\\documents\\visual studio 2010\\Projects\\proj";
string localPath = new Uri(uriPath).LocalPath;
Run Code Online (Sandbox Code Playgroud)

  • 太好了!我有这个完全相同的问题和谷歌搜索疯狂,这很好. (3认同)
  • 你好.我希望该文件出现在www.xxx.com/sitemap.xml.这个东西在localhost上工作,但是在服务器上没有这样的目录.在这种情况下如何分类? (2认同)