简体   繁体   中英

Get/Detect Network drive Format NTFS or FAT

as the title implies i want to know wheter a network drive is NTFS or Fat format.

For local drives and paths i used DriveInfo and it worked fine but when you try to use drive info with a network drive path i got this exception:

System.Collections.ListDictionaryInternal -Object must be a root directory ("C:\\") or a drive letter ("C").

public static bool IsNtfsDrive(string directory)
{
  try
  {
    // Get drive info
    var driveInfo = new DriveInfo(directory);

    // Check if drive is NTFS partition
    return driveInfo.DriveFormat == Cntfs;
  }
  catch (Exception e)
  {
    Console.WriteLine("Data: " + e.Data + " -Message: " + e.Message);
    return false;
  }
}

Found a similar question here:

DriveInfo.GetDrives

Is your application running as a different user (For example an asp.net website)? If it is, are the drives actually mapped for that user? You might find that the drives are mapped for you but they aren't actually mapped for the user your application is running as.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM