Uri.IsUnc Property

Definition

Gets a value that indicates whether the specified Uri is a universal naming convention (UNC) path.

public bool IsUnc { get; }

Property Value

true if the Uri is a UNC path; otherwise, false.

Exceptions

This instance represents a relative URI, and this property is valid only for absolute URIs.

Examples

The following example creates a Uri instance and determines whether it is a UNC path.

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

Remarks

The IsUnc property is true if the specified Uri instance is a UNC path (such as \\server\folder, //server, or file://server/folder). This property always returns true if the URI has the file:// scheme and specifies a host component.

Applies to