Uri.LocalPath Property

July 28, 2014

Gets a local operating-system representation of a file name.

Namespace:  System
Assembly:  System (in System.dll)

public string LocalPath { get; }

Property Value

Type: System.String
A String that contains the local operating-system representation of a file name.

ExceptionCondition
InvalidOperationException

This property is valid only for an absolute Uri instance.

The value returned by this property is unescaped. If the path is recognized as a Windows file path, all forward slashes (/) are replaced by backward slashes (\).

For the URI file://computer/file.ext, the absolute path is /file.ext and the local path is \\computer\file.ext.

LocalPath does not convert the forward slash (/) to a backslash (\). This is because file-based URIs (URIs of the form file://) are not allowed. Paths returned are relative paths.

The following example creates a Uri instance and writes the local path to the console.


Uri uriAddress2 =  new Uri("file://server/filename.ext");
outputBlock.Text += uriAddress2.LocalPath;
outputBlock.Text += "\n";

if (uriAddress2.IsUnc) 
    outputBlock.Text += "Uri is a UNC path\n";
else
    outputBlock.Text += "Uri is not a UNC path\n";


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft