asp.net读取驱动器列表
功能:列出本地硬盘上的所有驱动器。
本例子中主要用到System.IO。
源码如下:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
string[] strDrivers = Directory.GetLogicalDrives();//检索此计算机上格式为“<驱动器号>:\”的逻辑驱动器的名称
int nCount = strDrivers.Length;
string strResult = "";
strResult = "<ul>";
for (int i = 0; i < nCount; i++)
{
strResult += "<li>" + strDrivers[i] + "<br/>";
}
strResult += "</ul>";
Label1.Text = strResult;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>