asp.net在win2003中会以network service身份运行,可能需要为该帐户设置权限
FreeDiskSpaceViewer.aspx
--Code Begin----------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" %>
<html>
<head runat="server">
<title></title>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
ArrayList localDrives = new ArrayList();
foreach (System.IO.DriveInfo drive in drives)
{
if (drive.DriveType == System.IO.DriveType.Fixed)
{
MyDriveInfo di = new MyDriveInfo();
di.Name = drive.Name;
di.AvailableFreeSpace = drive.AvailableFreeSpace / 1024m / 1024m / 1024m;
di.TotalSize = drive.TotalSize / 1024m / 1024m / 1024m;
localDrives.Add(di);
}
}
GridView1.DataSource = localDrives;
GridView1.DataBind();
}
public class MyDriveInfo
{
private string _name;
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
private decimal _availableFreeSpace;
public decimal AvailableFreeSpace
{
get
{
return _availableFreeSpace;
}
set
{
_availableFreeSpace = value;
}
}
private decimal _totalSize;
public decimal TotalSize
{
get
{
return _totalSize;
}
set
{
_totalSize = value;
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<span>Drive Information</span>
<asp:GridView ID="GridView1"
runat="server" AutoGenerateColumns="false">
<%-- Name DriveFormat IsReady AvailableFreeSpace TotalFreeSpace TotalSize VolumeLabel --%>
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="AvailableFreeSpace" HeaderText="AvailableFreeSpace" DataFormatString="{0:n2} g" />
<asp:BoundField DataField="TotalSize" HeaderText="TotalSize" DataFormatString="{0:n2} g" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>--Code End----------------------------------------------------