Doron Yaacoby Doron Yaacoby - 8 months ago 34
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:).


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;