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: 
Don't know if there's a more efficient way of doing this, but it seems to work for me:

```
    IPAddress[] host;
    IPAddress[] local;
    bool isLocal = false;

    host = Dns.GetHostAddresses(uri.Host);
    local = Dns.GetHostAddresses(Dns.GetHostName());

    foreach (IPAddress hostAddress in host)
    {
        if (IPAddress.IsLoopback(hostAddress))
        {
            isLocal = true;
            break;
        }
        else
        {
            foreach (IPAddress localAddress in local)
            {
                if (hostAddress.Equals(localAddress))
                {
                    isLocal = true;
                    break;
                }
            }

            if (isLocal)
            {
                break;
            }
        }
    }

```
Here is how I addressed a similar need.

```
        internal static bool IsFileRemote(string path)
    {
            if (String.IsNullOrEmpty(path))
            {
                return false;
            }
            if (new Uri(path).IsUnc)
            {
                return true;
            }
            if (new DriveInfo(path).DriveType == DriveType.Network)
            {
                return true;
            }
            return false;
    }

```