2009-04-28 187 views

回答

22

使用Uri類,它似乎工作。它可以將任何文件路徑`文件:/// ......」語法在烏里它處理任何URI預期,並且有能力處理相對URI那要看還有什麼你正在嘗試做的。這條道路

(更新以顯示相對使用的URI):

string fileName = @"c:\temp\myfile.bmp"; 
string relativeFile = @".\woohoo\temp.bmp"; 
string addressName = @"http://www.google.com/blahblah.html"; 

Uri uriFile = new Uri(fileName); 
Uri uriRelative = new Uri(uriFile, relativeFile); 
Uri uriAddress = new Uri(addressName); 

Console.WriteLine(uriFile.ToString()); 
Console.WriteLine(uriRelative.ToString()); 
Console.WriteLine(uriAddress.ToString()); 

給了我這樣的輸出:

file:///c:/temp/myfile.bmp 
file:///c:/temp/woohoo/temp.bmp 
http://www.google.com/blahblah.html 
+0

該文件:///事情是......不方便,但我可以,如果我必須接受它。我真的很希望更多的東西,直接爲它設置+1 – BCS 2009-04-28 19:17:09