connectseekers.com

Sunday, 22 March 2020

Detect Pen Drive(Flash Drive) in C#.Net

3/22/2020 - By Pranav Singh 0


This article will show you how you can detect pen drive in windows using c#.net. In this article I will show you how you can detect all the detail of a pen drive attached in your machine.

So first we will create new application and design the form as show as below.



Now put the code as shown below.

using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void btnShowDetail_Click(object sender, EventArgs e)
        {
            var drives = DriveInfo.GetDrives().Where(drive => drive.IsReady && drive.DriveType == DriveType.Removable);
            if (drives.FirstOrDefault() != null)
            {

            }
            else
            {
                MessageBox.Show("No Pendrive found..");
            }
        }
    }
}

In above code below mention piece code is responsible for detecting the pen drive.
var drives = DriveInfo.GetDrives().Where(drive => drive.IsReady && drive.DriveType == DriveType.Removable);

Now we have done run the application and check the output. Now try to retest the pen drive without connecting it.


Now connect the pen drive and try to get the detail.


DOWNLOAD


Tags: ,
About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top