簡體   English   中英

例外:“不支持URI格式”

[英]Exception: “URI formats are not supported”

我有一個指向dir的絕對本地路徑: "file:\\\\C:\\\\Users\\\\john\\\\documents\\\\visual studio 2010\\\\Projects\\\\proj"

但是當我嘗試將它扔進DirectoryInfo的ctor時,我得到了“不支持URI格式”的例外。

我用Google搜索並查看了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 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 { }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM