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