C# 例外:“不支持 URI 格式”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12560664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 23:41:09  来源:igfitidea点击:

Exception: "URI formats are not supported"

c#.net.net-4.0

提问by Howie

I have an absolute local path pointing to a dir: "file:\\C:\\Users\\john\\documents\\visual studio 2010\\Projects\\proj"

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

But when I try to throw it into DirectoryInfo's ctor I get the "URI formats are not supported" exception.

但是,当我尝试将其放入DirectoryInfoctor 时,我收到“不支持 URI 格式”异常。

I googled and looked on SO, but I only see solutions with remote paths, not local ones. I'd expect a conversion method of some sort...

我用谷歌搜索并查看了 SO,但我只看到带有远程路径的解决方案,而不是本地路径。我希望有某种转换方法......

采纳答案by Marc Gravell

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

回答by Hardeep Singh

Try This

尝试这个

ImagePath = "http://localhost/profilepics/abc.png";
   HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ImagePath);
          HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream receiveStream = response.GetResponseStream();

回答by Robert Peter Bronstein

I solved the same error with the Path.Combine(MapPath()) to get the physical file path instead of the http:///www one.

我用 Path.Combine(MapPath()) 解决了同样的错误,以获取物理文件路径而不是http:///www 。

回答by Badr Bouaichi

     string ImagePath = "";

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ImagePath);
        string a = "";
        try
        {
            HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
            Stream receiveStream = response.GetResponseStream();
            if (receiveStream.CanRead)
            { a = "OK"; }
        }

        catch { }