asp.net(C#)中如何获得一个文件夹的大小值(字节)? [ZT]
2007-09-29 20:41
549 查看
size.aspx文件代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="size.aspx.cs" Inherits="size" %>
<!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="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
size.aspx.cs后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
public partial class size : System.Web.UI.Page
public int str = 0;
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
string dpath = Server.MapPath(".");
Label1.Text = getsize(dpath).ToString();
}
}
private int getsize(string dirp)
DirectoryInfo mydir = new DirectoryInfo(dirp);
foreach (FileSystemInfo fsi in mydir.GetFileSystemInfos())
if (fsi is FileInfo)
FileInfo fi = (FileInfo)fsi;
str+=int.Parse(fi.Length.ToString());
}
else
DirectoryInfo di = (DirectoryInfo)fsi;
string new_dir = di.FullName;
getsize(new_dir);
}
}
return str;
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="size.aspx.cs" Inherits="size" %>
<!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="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
size.aspx.cs后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
public partial class size : System.Web.UI.Page
public int str = 0;
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
string dpath = Server.MapPath(".");
Label1.Text = getsize(dpath).ToString();
}
}
private int getsize(string dirp)
DirectoryInfo mydir = new DirectoryInfo(dirp);
foreach (FileSystemInfo fsi in mydir.GetFileSystemInfos())
if (fsi is FileInfo)
FileInfo fi = (FileInfo)fsi;
str+=int.Parse(fi.Length.ToString());
}
else
DirectoryInfo di = (DirectoryInfo)fsi;
string new_dir = di.FullName;
getsize(new_dir);
}
}
return str;
}
}
相关文章推荐
- 在asp.net(C#)中怎么获得一个目录的大小?
- 在asp.net(C#)中怎么获得一个目录的大小?
- [ASP.NET]在asp.net(C#)中怎么获得一个目录的大小?
- ASP.NET 如何获得文件夹大小
- ASP.NET如何获得一个表的结构信息
- asp.net 如何改变GridView搜索出来关键字的颜色?就像百度似的,我获得的是一个集合,改变集合中关键字的集合
- ASP.NET中如何让一个服务期端输入框获得焦点?
- 如何在ASP调用一个用C#.NET(2005)写成的类?
- asp.net C# 中删除一个文件夹里的所有内容
- asp.net c#后台页代码 如何使用confirm这样的函数,并获得其bool返回值?
- 关于asp.net(c#),webconfig中如何定义一个字符串让所有页面共同使用?
- ASP.NET如何获得一个表的结构信息
- asp.net 得到一个文件夹下的所有文件夹及子文件夹名,得到所有文件名,文件大小,文件夹大小
- 一个ASP.NET控件元素如何获得焦点的问题
- asp.net 得到一个文件夹下的所有文件夹及子文件夹名,得到所有文件名,文件大小,文件夹大小
- .Net C# - 如何获得一个事件(Event)的订阅者(Handler)的数量和列表?(例程)
- .C#中如何给时间变量赋一个空值ASP.NET 2.0
- c#(Asp.net)多个Excel文件合并到一个新的excel中
- asp.net(C#)遍历文件夹下所有文件,绑定到GRIDVIEW并排序
- 如何使用 ASP.NET、ADO.NET 和 Visual C# .NET 查询和显示 Excel 数据