0

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;
  }
}

1 Answers1

0

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.

Richard
  • 58
  • 2
  • 10
  • Hi, I´m on a simple test console application, I´m trying to do this without mapping drives, like how DriveInfo only with a path cant tell if the format is NTFS or FAT. – Chris Andrade Jan 30 '18 at 21:13
  • The path we need to check could be mapped but there is no guarantee that it is. Its just a path from which a file can be loaded into our application. If the file is stored on a NTFS drive we try to access some metadata stored in ads streams. – Chris Andrade Jan 30 '18 at 21:40
  • How are you calling IsNtfsDrive(string directory)? If I call the method with my mapped drive letter "Z", it works. However, if I try using a UNC path such as \\SERVER001\E, I get the same error you are getting. – Richard Jan 30 '18 at 21:47
  • Yes that is the problem you cant use UNC on Driveinfo so we are trying to achive this, o something similiar for the reasons mentioned above. – Chris Andrade Jan 30 '18 at 22:00
  • You could read the registry HKEY_CURRENT_USER => Network to get the list of mapped drives for your user, then check your UNC path for a match (i.e. against the RemotePath value). This way you could find the drive letter mapping and use it in your function call. – Richard Jan 30 '18 at 22:33