89

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

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

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

4

4 回答 4

190
string uriPath =
    "file:\\C:\\Users\\john\\documents\\visual studio 2010\\Projects\\proj";
string localPath = new Uri(uriPath).LocalPath;
于 2012-09-24T07:37:49.440 回答
1

试试这个

ImagePath = "http://localhost/profilepics/abc.png";
   HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ImagePath);
          HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream receiveStream = response.GetResponseStream();
于 2017-07-27T07:32:11.810 回答
0

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

于 2019-05-24T01:08:25.790 回答
0
     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 { }
于 2019-09-10T11:25:27.230 回答