In this article we will discuss how to get driver information in C#.Net by using System.IO class.
In my previous articles I have explained how to add user to a group in Active directory in C#.Net, Anonymous types in C#.Net, File upload and Thumbnail creation in Asp.Net.
To work with files and directory, Microsoft provides System.IO namespace. So we can use classes like DriveInfo, DirectoryInfo, and FileInfo to work with files and directories in C#.Net.
To Get the driver info we can use GetDrives() method of DriveInfo class like below.
HTML Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="IOSamples.aspx.cs" Inherits="IOSamples" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblDrivers" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
.CS Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class IOSamples : System.Web.UI.Page
{
string drivers = "";
protected void Page_Load(object sender, EventArgs e)
{
string allDrivers = GetDriverInfo();
lblDrivers.Text = allDrivers;
}
string GetDriverInfo()
{
foreach (var drive in DriveInfo.GetDrives())
{
drivers += "Driver Name: " + drive.Name + " Drive Type: " + drive.DriveType +" "+ "\n" + "<br/>";
}
return drivers;
}
}
It will show the result as shown in the figure below.
In my previous articles I have explained how to add user to a group in Active directory in C#.Net, Anonymous types in C#.Net, File upload and Thumbnail creation in Asp.Net.
To work with files and directory, Microsoft provides System.IO namespace. So we can use classes like DriveInfo, DirectoryInfo, and FileInfo to work with files and directories in C#.Net.
To Get the driver info we can use GetDrives() method of DriveInfo class like below.
HTML Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="IOSamples.aspx.cs" Inherits="IOSamples" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblDrivers" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
.CS Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class IOSamples : System.Web.UI.Page
{
string drivers = "";
protected void Page_Load(object sender, EventArgs e)
{
string allDrivers = GetDriverInfo();
lblDrivers.Text = allDrivers;
}
string GetDriverInfo()
{
foreach (var drive in DriveInfo.GetDrives())
{
drivers += "Driver Name: " + drive.Name + " Drive Type: " + drive.DriveType +" "+ "\n" + "<br/>";
}
return drivers;
}
}
It will show the result as shown in the figure below.
0 on: "Get driver info in C#.Net"