Uri.LocalPath 屬性

定義

取得檔案名稱的本機作業系統表示。

C#
public string LocalPath { get; }

屬性值

String

檔案名的本機作業系統標記法。

例外狀況

這個執行個體代表相對的 URI,而這個屬性只適用於絕對 URI。

範例

下列範例會 Uri 建立 實例,並將本機路徑寫入主控台。

C#
Uri uriAddress2 =  new Uri("file://server/filename.ext");
Console.WriteLine(uriAddress2.LocalPath);
Console.WriteLine("Uri {0} a UNC path", uriAddress2.IsUnc ? "is" : "is not");
Console.WriteLine("Uri {0} a local host", uriAddress2.IsLoopback ? "is" : "is not");
Console.WriteLine("Uri {0} a file", uriAddress2.IsFile ? "is" : "is not");
// The example displays the following output:
//    \\server\filename.ext
//    Uri is a UNC path
//    Uri is not a local host
//    Uri is a file

備註

這個屬性所傳回的值是未逸出的。 如果路徑被辨識為Windows檔案路徑,所有正斜線 (/) 都會由回 \ 斜線取代 () 。

針對 URI file://computer/file.ext ,絕對路徑為 /file.ext ,而本機路徑為 \\computer\file.ext

適用於

產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0