浏览量: 次
using System;
using System.Data;
using System.Configuration;
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//初始化文件夹信息
InitFolderInfo();
//初始化上传限制信息
InitUploadLimit();
//初始化列表框控件文件列表信息
InitFileList();
}
}
#region 初始化文件夹信息
private void InitFolderInfo()
{
//从config中读取文件上传路径
string strFileUpladPath = ConfigurationManager.AppSettings["FileUplodePath"].ToString();
//如果上传文件夹不存在,则根据config创建一个
if(!Directory.Exists(Server.MapPath(strFileUpladPath)))
{
Directory.CreateDirectory(Server.MapPath(strFileUpladPath));
}
//将虚拟路径转换为物理路径
string strFilePath = Server.MapPath(strFileUpladPath);
//从config里读取文件夹容量限制
double iFolderSizeLimit = Convert.ToInt32(ConfigurationManager.AppSettings["FolderSizeLimit"]);
//声明文件夹已经使用的容量
double iFolderCurrentSize = 0;
//获取文件夹中的所有文件
FileInfo[] arrFiles = new DirectoryInfo(strFilePath).GetFiles();
//循环文件获已经使用的容量
foreach (FileInfo fi in arrFiles)
{
iFolderCurrentSize += Convert.ToInt32(fi.Length / 1024);
}
上一篇:aspx 页面弹出窗口代码大全下一篇:asp.net 文件管理
[声明]本网转载网络媒体稿件是为了传播更多的信息,此类稿件不代表本网观点,本网不承担此类稿件侵权行为的连带责任。故此,如果您发现本网站的内容侵犯了您的版权,请您的相关内容发至此邮箱【27535611@qq.com】,我们在确认后,会立即删除,保证您的版权。