MultiUpload.aspx.cs
上传用户:whjkdz
上传日期:2013-05-19
资源大小:79k
文件大小:2k
- using System;
- using System.IO;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using Sunrise.Web.Upload;
- namespace SunriseUploadSample
- {
- /// <summary>
- /// MultiUpload 的摘要说明。
- /// </summary>
- public class MultiUpload : Page
- {
- protected Table tbFileList;
- protected System.Web.UI.WebControls.Button Button1;
- protected Button btnUpload;
- private void Page_Load(object sender, EventArgs e)
- {
- //建立Helper对象
- UploadHelper uploadHelper = new UploadHelper();
- //如需要显示进度条
- uploadHelper.RegisterProgressBar(btnUpload, false);
- }
- #region Web 窗体设计器生成的代码
- protected override void OnInit(EventArgs e)
- {
- //
- // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.btnUpload.Click += new System.EventHandler(this.btnUpload_Click);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- private void btnUpload_Click(object sender, EventArgs e)
- {
- string path = Path.Combine(Server.MapPath("."), "UploadFile");
- if (!Directory.Exists(path))
- {
- Directory.CreateDirectory(path);
- }
- //获取上传的所有文件,"files"是<input type=file>的name属性
- UploadFileCollection uploadFiles = UploadHelper.GetUploadFileList("files");
- foreach (UploadFile file in uploadFiles)
- {
- TableRow tr = new TableRow();
- TableCell[] tc = new TableCell[2] {new TableCell(), new TableCell()};
- tc[0].Text = Path.GetFileName(file.FileName);
- tc[1].Text = file.ContentLength.ToString("###,###") + " K bytes";
- tr.Cells.AddRange(tc);
- tbFileList.Rows.Add(tr);
- //保存文件
- file.SaveAs(Path.Combine(path, Path.GetFileName(file.FileName)));
- }
- }
- }
- }