The Directory class exposes static methods to create , move and enumerate directories and subdirectories.
GetLogicalDrives : Retrieves the name of the logical drives on this computer in the form "<drive letter>:\"
GetLogicalDrives : Retrieves the name of the logical drives on this computer in the form "<drive letter>:\"
How to access system drives in WebApplication
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default9.aspx.cs" Inherits="Default9" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="GetLogical Drives" OnClick="Button1_Click" />
<br />
<br />
<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
</div>
</form>
</body>
</html>
CodeBehind page
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default9 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string[] str = Directory.GetLogicalDrives();
foreach (string item in str)
{
DropDownList1.Items.Add(item);
}
}
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="GetLogical Drives" OnClick="Button1_Click" />
<br />
<br />
<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
</div>
</form>
</body>
</html>
CodeBehind page
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default9 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string[] str = Directory.GetLogicalDrives();
foreach (string item in str)
{
DropDownList1.Items.Add(item);
}
}
}
Output of the program is
How to access system drives in Window Application
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] str = Directory.GetLogicalDrives();
foreach (string item in str)
{
comboBox1.Items.Add(item);
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] str = Directory.GetLogicalDrives();
foreach (string item in str)
{
comboBox1.Items.Add(item);
}
}
}
}
Tidak ada komentar:
Posting Komentar