asp.net代码练习 work070 文件系统演示
webform1.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="work070.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="DriverName" HeaderText="分区名称"/>
<asp:BoundField DataField="DriverType" HeaderText="分区类型"/>
<asp:BoundField DataField="DriverFormat" HeaderText="文件系统"/>
<asp:BoundField DataField="VolumeLabel" HeaderText="卷标"/>
<asp:BoundField DataField="TotalSize" HeaderText="总容量"/>
<asp:BoundField DataField="AvailableFreeSpace" HeaderText="可用容量"/>
<asp:BoundField DataField="TotalFreeSpace" HeaderText="空闲容量"/>
<asp:BoundField DataField="Percent" HeaderText="剩余百分比" DataFormatString="{0}%"/>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace work070
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
System.IO.DriveInfo[] drivers = System.IO.DriveInfo.GetDrives();
System.Data.DataTable table1 = new System.Data.DataTable();
//磁盘分区名称
table1.Columns.Add("DriverName",typeof(string));
//分区类型
table1.Columns.Add("DriverType", typeof(string));
//分区文件格式
table1.Columns.Add("DriverFormat", typeof(string));
//卷标
table1.Columns.Add("VolumeLabel", typeof(string));
//磁盘可用容量
table1.Columns.Add("AvailableFreeSpace",typeof(long));
//磁盘空闲容量
table1.Columns.Add("TotalFreeSpace", typeof(long));
//磁盘总容量
table1.Columns.Add("TotalSize", typeof(long));
//剩余百分比
table1.Columns.Add("Percent", typeof(float));
foreach (System.IO.DriveInfo info in drivers)
{
System.Data.DataRow row1 = table1.NewRow();
row1["DriverName"] = info.Name;
row1["DriverType"] = info.DriveType;
row1["DriverFormat"] = info.DriveFormat;
row1["VolumeLabel"] = info.VolumeLabel;
row1["AvailableFreeSpace"] = info.AvailableFreeSpace;
row1["TotalFreeSpace"] = info.TotalFreeSpace;
row1["TotalSize"] = info.TotalSize;
row1["Percent"] = (info.TotalFreeSpace * 100) / info.TotalSize;
table1.Rows.Add(row1);
}
GridView1.DataSource = table1;
GridView1.DataBind();
}
}
}
}
https://blog.51cto.com/u_15356972/3775782
页:
[1]