我有一个指向目录的绝对本地路径: "file:\\C:\\Users\\john\\documents\\visual studio 2010\\Projects\\proj"
但是,当我尝试将其放入DirectoryInfo的ctor中时,出现“不支持URI格式”异常。
我用谷歌搜索并查看了SO,但是我只看到带有远程路径的解决方案,而不是本地路径。我希望某种转换方法...
Answers:
string uriPath =
"file:\\C:\\Users\\john\\documents\\visual studio 2010\\Projects\\proj";
string localPath = new Uri(uriPath).LocalPath;
我用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 { }