SigleUpload.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>
- /// SigleUpload 的摘要说明。
- /// </summary>
- public class SigleUpload : Page
- {
- protected Table tbFileList;
- protected Button btnUpload;
- private void Page_Load(object sender, EventArgs e)
- {
- //如需要显示进度条
- // new 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 EventHandler(this.btnUpload_Click);
- this.Load += new 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属性
- UploadFile uploadFile = UploadHelper.GetUploadFile("file1");
- if(uploadFile != null)
- {
- TableRow tr = new TableRow();
- TableCell[] tc = new TableCell[2] {new TableCell(), new TableCell()};
- tc[0].Text = Path.GetFileName(uploadFile.FileName);
- tc[1].Text = uploadFile.ContentLength.ToString("###,###") + " K bytes";
- tr.Cells.AddRange(tc);
- tbFileList.Rows.Add(tr);
- //Save file
- uploadFile.SaveAs(Path.Combine(path, Path.GetFileName(uploadFile.FileName)));
- }
- }
- }
- }