Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从所选文件路径c#winform获取光盘的卷标签_C#_Asp.net_Winforms_Path_Drive - Fatal编程技术网

从所选文件路径c#winform获取光盘的卷标签

从所选文件路径c#winform获取光盘的卷标签,c#,asp.net,winforms,path,drive,C#,Asp.net,Winforms,Path,Drive,我必须从路径中获取所选光盘的卷标。例如,我有一张名为LocalDisc(E)的光盘,我从这个文件夹中选择了一个文件(E:\Pictures\mypic.png) 有没有办法获取所选“E”驱动器的卷标签?在这里,它应该是LocalDisc。 我有下面的代码来获取所有PC的卷标 foreach (var drive in DriveInfo.GetDrives()) { Console.WriteLine("Drive Name: {0}", drive.V

我必须从路径中获取所选光盘的卷标。例如,我有一张名为LocalDisc(E)的光盘,我从这个文件夹中选择了一个文件(E:\Pictures\mypic.png)

有没有办法获取所选“E”驱动器的卷标签?在这里,它应该是LocalDisc。 我有下面的代码来获取所有PC的卷标

      foreach (var drive in DriveInfo.GetDrives())
        {
       Console.WriteLine("Drive Name: {0}", drive.VolumeLabel);\\LocalDisc
        }
但如何从选定的文件路径获取它

 string selectedFilePath="E:\\Pictures\\mypic.png";
 string RootFolder=Path.GetPathRoot(selectedFilePath);\\ E
 string GetSelectedPath = Path.GetDirectoryName(selectedFilePath);\\E:\\Pictures\\

类我的问题是如何从路径
var-drvInfo=new-driveinfo(path.GetPathRoot([您的路径]);
或简单地
var-drvInfo=new-driveinfo([您的路径]);
。所有驱动器:
var-allDrives=driveinfo.GetDrives();