Doron Yaacoby Doron Yaacoby - 1 year ago 75
C# Question

Easiest way in C# to find out if an app is running from a network drive?

I want to programmatically find out if my application is running from a network drive. What is the simplest way of doing that? It should support both UNC paths (

) and mapped network drives (Z:).

Answer Source

This is my current method of doing this, but it feels like there should be a better way.

private bool IsRunningFromNetworkDrive()
        var dir = AppDomain.CurrentDomain.BaseDirectory;
        var driveLetter = dir.First();
        if (!Char.IsLetter(driveLetter))
            return true;
        if (new DriveInfo(driveLetter.ToString()).DriveType == DriveType.Network)
            return true;
        return false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download