0

I'm working on an application that runs off of a thumb drive. The very first step in the application is to select the drive letter of the thumb drive. That populates a variable which is used throughout the program to note various paths on the thumb drive.

Is there a way to code this in C# to automatically see the drive letter that the thumb drive represents and therfore auto populates that Drv variable?

Thanks,
Hendo

2
Contributors
4
Replies
5
Views
4 Years
Discussion Span
Last Post by Hendo
0

The driveinfo class should give you what you need. Probably, the easiest to use would be the volumelabel property. Here's the info on it

Edited by tinstaafl

0

Will that work in .NET 2.o?
EDIT yeah, they have the 2.0 section in that link. Now I have to figure out how to grab the drive letter and make it a useable variable. Is that right?

Edited by Hendo

0

yes, you can try this:

            string drv="";
            DriveInfo[] allDrives = DriveInfo.GetDrives();
            foreach(DriveInfo d in allDrives)
            {
                if (d.IsReady)
                {
                    if (d.VolumeLabel == "MyThumbDrive")
                    {
                        drv = d.RootDirectory.ToString();
                        break;
                    }
                }
            }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.