异常: “不支持 URI 格式”

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

但是,当我尝试将其放入 DirectoryInfo的 ctor 时,会出现“ URI 格式不受支持”异常。

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

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

Try This

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

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

     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 { }