Question: What's the best way, using C# or other .NET language, to determine if a file path string is on the local machine or a remote server?

It's possible to determine if a path string is UNC using the following:

```
new Uri(path).IsUnc

```

That works great for paths that start with C:\ or other drive letter, but what about paths like:

```
\\machinename\sharename\directory
\\10.12.34.56\sharename\directory

```

...where both refer to the local machine - these are UNC paths but are still local.

Answer: 
.NET 3.5 version of Eric's answer with an extra check whether the host exists:

```
    private bool IsLocalHost(string input)
    {
        IPAddress[] host;
        //get host addresses
        try { host = Dns.GetHostAddresses(input); }
        catch (Exception) { return false; }
        //get local adresses
        IPAddress[] local = Dns.GetHostAddresses(Dns.GetHostName()); 
        //check if local
        return host.Any(hostAddress => IPAddress.IsLoopback(hostAddress) || local.Contains(hostAddress));
    }

```
The following should work for mapped drives and for UNC paths.

```
private static bool IsLocalPath(String path)
{
    if (!PathIsUNC(path))
    {
        return !PathIsNetworkPath(path);
    }

    Uri uri = new Uri(path);
    return IsLocalHost(uri.Host); // Refer to David's answer
}

[DllImport("Shlwapi.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool PathIsNetworkPath(String pszPath);

[DllImport("Shlwapi.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool PathIsUNC(String pszPath);

```