How to get the listed network drive name

Asked

Viewed 35 times

-1

I’m listing my network units via C# in a TreeView. Today it is appearing as follows:

listagem

But I want the full name to appear:

  • C:\Disco Local
  • J:\Pen Drive X

I’m using the following code to fetch the drives:

foreach (DriveInfo drv in DriveInfo.GetDrives())
{
                if (drv.IsReady)
                {
                    TreeNode node = new TreeNode();
                    node.Tag = drv.RootDirectory;
                    node.SelectedImageIndex = 0;
                    node.Text = drv.Name;
                    TwCaminhoArquivo.Nodes.Add(node);

                }
}

Whereas TwCaminhoArquivo is my TreeView.

Does anyone have any idea how I do it?

1 answer

0

You can use the property VolumeLabelas below.

    foreach (DriveInfo drv in DriveInfo.GetDrives())
    {
        if (drv.IsReady)
        {
            TreeNode node = new TreeNode();
            node.Tag = drv.RootDirectory;
            node.SelectedImageIndex = 0;
            node.Text = $"{drv.VolumeLabel} - {drv.Name}";
            treeView1.Nodes.Add(node);
        }
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.