Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How Can We Get All Drives information in Form of Tree View in .NET 2.0.

Author: DevASP
Download Source Code : 617_DriveInfo.zip

In this simple article you will learn that how you can Get All Drives information in Form of Tree View.

Simply just create New Project of console application in C#.

 

Drag two buttons and one Tree View on form.Now just write code against these events

 

 

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DevAsp Product";

            this.BackColor = Color.Gray;

           

            System.IO.DriveInfo[] allDrives = System.IO.DriveInfo.GetDrives();

            int i = 0;

            //DriveInfo allDrives = DriveInfo.GetDrives();

            foreach (System.IO.DriveInfo d in allDrives)

            {

               

                treeView1.ForeColor = Color.Blue;

                treeView1.Nodes.Add("Drive "+d.Name);

                    

 

               

                treeView1.Nodes[i].Nodes.Add("Type"  );

                treeView1.Nodes[i].Nodes.Add("           " + d.DriveType );

                

                if (d.IsReady == true)

                {

                    treeView1.ForeColor = Color.Red ;

                    treeView1.Nodes[i].Nodes.Add("Lablel");

                    treeView1.Nodes[i].Nodes.Add("           " + d.VolumeLabel );

                   

                    treeView1.ForeColor = Color.Cyan ;

                    treeView1.Nodes[i].Nodes.Add("Format");

                    treeView1.Nodes[i].Nodes.Add("           " + d.DriveFormat);

                   

                    treeView1.ForeColor = Color.LightBlue ;

                    treeView1.Nodes[i].Nodes.Add("Free Space For Current User");

                    treeView1.Nodes[i].Nodes.Add("           " + d.AvailableFreeSpace.ToString() + " Bytes");

                    

                    treeView1.ForeColor = Color.BlueViolet ;

                    treeView1.Nodes[i].Nodes.Add("Total Free Space");

                    treeView1.Nodes[i].Nodes.Add("           " + d.TotalFreeSpace.ToString() + " Bytes");

 

                    treeView1.ForeColor = Color.BlueViolet;

                    treeView1.Nodes[i].Nodes.Add("Total Size of Drive");

                    treeView1.Nodes[i].Nodes.Add("           "+d.TotalSize.ToString() + " Bytes");

      

                }

               i++;

 

 

 

            }

      

 

           

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            treeView1.ExpandAll();

            

        }

 

        private void button2_Click(object sender, EventArgs e)

        {

            treeView1.Refresh();

        }

Article Comments
Very clear and easily readable

Posted on 2/8/2007 12:54:06 AM by vijaya

excellent

Posted on 4/13/2010 1:06:27 AM by avijeet

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Creating Data Table and Columns on Runtime and Link with Data Grid in .NET 2.0.

Disclaimer - Privacy
© 2002-2017 DevASP.net