【发布时间】:2012-09-15 15:43:14
【问题描述】:
我有一个指向目录的绝对本地路径:"file:\\C:\\Users\\john\\documents\\visual studio 2010\\Projects\\proj"
但是当我尝试将其放入 DirectoryInfo 的 ctor 时,我得到“不支持 URI 格式”异常。
我搜索并查看了 SO,但我只看到远程路径的解决方案,而不是本地路径。我希望有某种转换方法...
【问题讨论】:
我有一个指向目录的绝对本地路径:"file:\\C:\\Users\\john\\documents\\visual studio 2010\\Projects\\proj"
但是当我尝试将其放入 DirectoryInfo 的 ctor 时,我得到“不支持 URI 格式”异常。
我搜索并查看了 SO,但我只看到远程路径的解决方案,而不是本地路径。我希望有某种转换方法...
【问题讨论】:
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 { }
【讨论】:
我用 Path.Combine(MapPath()) 解决了同样的错误,以获取物理文件路径而不是 http:/// www 。
【讨论】:
试试这个
ImagePath = "http://localhost/profilepics/abc.png";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ImagePath);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
【讨论】:
string uriPath =
"file:\\C:\\Users\\john\\documents\\visual studio 2010\\Projects\\proj";
string localPath = new Uri(uriPath).LocalPath;
【讨论】: