Uri.LocalPath Property

Definition

取得檔案名稱的本機作業系統表示。Gets a local operating-system representation of a file name.

public:
 property System::String ^ LocalPath { System::String ^ get(); };
public string LocalPath { get; }
member this.LocalPath : string
Public ReadOnly Property LocalPath As String

Property Value

String

String,包含檔案名稱在本機作業系統上的表示。A String that contains the local operating-system representation of a file name.

Exceptions

這個執行個體代表相對的 URI,而這個屬性只適用於絕對 URI。This instance represents a relative URI, and this property is valid only for absolute URIs.

Examples

下列範例會建立 Uri 實例,並將本機路徑寫入主控台。The following example creates a Uri instance and writes the local path to the console.

Uri^ uriAddress2 = gcnew Uri( "file://server/filename.ext" );
Console::WriteLine( uriAddress2->LocalPath );
Console::WriteLine( "Uri {0} a UNC path", uriAddress2->IsUnc ? (String^)"is" : "is not" );
Console::WriteLine( "Uri {0} a local host", uriAddress2->IsLoopback ? (String^)"is" : "is not" );
Console::WriteLine( "Uri {0} a file", uriAddress2->IsFile ? (String^)"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
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
Dim uriAddress2 As New Uri("file://server/filename.ext")
Console.WriteLine(uriAddress2.LocalPath)
Console.WriteLine("Uri {0} a UNC path", IIf(uriAddress2.IsUnc, "is", "is not")) 'TODO: For performance reasons this should be changed to nested IF statements
Console.WriteLine("Uri {0} a local host", IIf(uriAddress2.IsLoopback, "is", "is not")) 'TODO: For performance reasons this should be changed to nested IF statements
Console.WriteLine("Uri {0} a file", IIf(uriAddress2.IsFile, "is", "is not")) 'TODO: For performance reasons this should be changed to nested IF statements
' The example displays the following output:
'    \\server\filename.ext
'    Uri is a UNC path
'    Uri is not a local host
'    Uri is a file

Remarks

這個屬性所傳回的值是非預設的。The value returned by this property is unescaped. 如果將路徑辨識為 Windows 檔案路徑,則會以反\斜杠(/)取代所有正斜線(/)。If the path is recognized as a Windows file path, all forward slashes (/) are replaced by backward slashes (\).

對於 URI file://computer/file.ext,絕對路徑是 /file.ext,而本機路徑則是 \\computer\file.extFor the URI file://computer/file.ext, the absolute path is /file.ext and the local path is \\computer\file.ext.

Applies to