简体   繁体   中英

how to get Network mapped drive VolumeLabel in C#?

So for example, if i have drive Z:NetworkDrive, which mapped to shared folder on another server, and i want to return volumelabel "NetworkDrive". Next code seems to work:

 foreach (DriveInfo drive in drives)
            {
                if (drive.DriveType == DriveType.Network)
                    mappedDrivesNames.Add(drive.VolumeLabel);
            }

But it return the name of the first shared folder from the list on server. Any ideas, why this happened?

If I just code

var drive = new DriveInfo("Z");
Console.WriteLine(drive.VolumeLabel);

It is showing me the Label of the Volume the network share is on. I have my drive Z: connected to a share on a Windows XP computer and the share is on a NTFS formatted drive. If I remove the label for that volume, the program will output an empty line.

I don't know what the expected result should be if the share is on a Linux machine. I don't know if Linux has something like a Label, but I don't think so.

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