Detecting whether the Path is local or remote

  • Thread starter Thread starter Hayato Iriumi
  • Start date Start date
H

Hayato Iriumi

Hello,
I'm trying to find out a way to detect whether a path passed resides locally
or on a remote machine.

I can easily detect a path like \\machinename\path to be remote. But when it
comes to a mapped path, I don't really know what to do about it.

Does anyone have any idea how to do this?
 
It will require some pInvoke work but, I recommend looking into the
GetDriveType() API function call. It should give you just what you want.

DL
 
I found a better one.

Here it is.

class Class1
{
[DllImport("shlwapi.dll")]
private static extern bool PathIsNetworkPath(string
Path);

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string strPath = "D:\\Temp";
bool blnIsLocalPath = IsLocalPath(strPath);
Console.WriteLine(blnIsLocalPath.ToString());
Console.ReadLine();

}

private static bool IsLocalPath(string Path)
{
return !PathIsNetworkPath(Path);
}
}
 
Back
Top