Thursday 25 May 2017

How to show computer all drives names in C#

Please follow the following steps!


1) First open a new project in Visual Studio (any version)

2) Drag a button to your form from toolbox and name it what you want!, in my case i have assigned button4

3) Click on the button which you have dragged

4) Write the following code in button4_click event



  private void button4_Click(object sender, EventArgs e)
        {

            //Initialise an array 
            string[] drives = System.IO.Directory.GetLogicalDrives();

            foreach (string str in drives)
            {
               //show the drives names in MessageBox
                MessageBox.Show(str);
            }
        }


No comments:

Post a Comment