石家庄建站平台

十年经验 优惠价格 贴心服务

服务热线 15383239821

asp.net文件上传下载及管理的实现

发布时间:2014-06-13    来源:

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 文件管理

还没开展互联网业务? 马上开始

关注多多建站公众号
扫码加好友