.netfilesystemsntfsnetwork-share

Determine the File System of a Network Path in .NET


For one of my pojects, I wish to take advantage of Alternate Data Streams, which is a feature of the NTFS file system that you can read more about at the given link. Since the feature is unique to NTFS, I need to do a preliminary check to make sure the directory that I'm working in is using that file system.

If the directory is on a local drive I can use System.IO.DriveInfo.DriveFormat to check the file system. However, if the directory is a network/UNC path such as \\Computer\Folder\Subfolder I can't use the DriveFormat class.

Is there any way I can find out the underlying file system for a network share? I haven't been able to find an answer anywhere.


Solution

  • If you look at the source of the DriveInfo class's DriveFormat property, you can see it is making a native call to GetVolumeInformationA in kernel32.dll to get the actual drive format.

    Calling to this function with a network UNC path such as \\Computer\Folder\ does give you the result that you want (include the trailing slash and do not include subfolders). It's a bit of work to do the same pattern with the dll import and proper error checking in your own code, but it is possible!