简体   繁体   English

获取/检测网络驱动器格式NTFS或FAT

[英]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. 如标题所示,我想知道网络驱动器是NTFS还是Fat格式。

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: 对于本地驱动器和路径,我使用DriveInfo,它工作正常,但是当您尝试将驱动器信息与网络驱动器路径一起使用时,出现此异常:

System.Collections.ListDictionaryInternal -Object must be a root directory ("C:\\") or a drive letter ("C"). System.Collections.ListDictionaryInternal -Object必须是根目录(“ C:\\”)或驱动器号(“ 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 DriveInfo.GetDrives

Is your application running as a different user (For example an asp.net website)? 您的应用程序是否以其他用户身份运行(例如asp.net网站)? 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. 您可能会发现驱动器已为您映射,但实际上并未为您的应用程序所运行的用户映射。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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