Asp.net源码专业站
首页->上传下载->51aspx多文件上传示例源码>>Default.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:51aspx多文件上传示例源码
当前文件:文件类型 51aspxUploads/Default.aspx.cs[3K,2009-6-12 11:31:08]打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Collections; 5using System.Data; 6using System.Drawing; 7using System.Web; 8using System.Web.Security; 9using System.Web.UI; 10using System.Web.UI.WebControls; 11using System.Web.UI.WebControls.WebParts; 12using System.Web.UI.HtmlControls; 13 14namespace _1aspxUploads 15{ 16 //51aspx.com多文件上传示例 17 public partial class _Default : System.Web.UI.Page 18 { 19 static public ArrayList hif = new ArrayList(); // 保存文件列表 20 public int filesUploaded = 0; // 上传文件的数量 21 22 protected void Page_Load(object sender, EventArgs e) 23 { 24 25 } 26 /// <summary> 27 /// 将要上传的文件添加到listbox中 28 /// </summary> 29 /// <param name="sender"></param> 30 /// <param name="e"></param> 31 32 protected void AddFile_Click(object sender, EventArgs e) 33 { 34 if (Page.IsPostBack == true) 35 { 36 hif.Add(FindFile); 37 FileList.Items.Add(FindFile.PostedFile.FileName); 38 } 39 else 40 { } 41 42 } 43 44 /// <summary> 45 /// 从listbox中删除指定的文件 46 /// </summary> 47 /// <param name="sender"></param> 48 /// <param name="e"></param> 49 protected void RemvFile_Click(object sender, EventArgs e) 50 { 51 if (FileList.SelectedIndex == -1) 52 { 53 TipInfo.Text = "错误 - 必须指定要删除的文件."; 54 return; 55 } 56 else if (FileList.Items.Count != 0) 57 { 58 hif.RemoveAt(FileList.SelectedIndex); 59 FileList.Items.Remove(FileList.SelectedItem.Text); 60 TipInfo.Text = ""; 61 } 62 63 } 64 65 /// <summary> 66 /// 循环上传listbox中的文件到指定的文件夹下 67 /// </summary> 68 /// <param name="sender"></param> 69 /// <param name="e"></param> 70 public void Upload_ServerClick(object sender, System.EventArgs e) 71 { 72 string baseLocation = Server.MapPath("UploadFiles/"); // 上传路径 73 string status = ""; // 上传成功后显示的文件列表 74 75 if ((FileList.Items.Count == 0) && (filesUploaded == 0)) 76 { 77 TipInfo.Text = "错误 - 必须指定要上传的文件."; 78 return; 79 } 80 else 81 { 82 foreach (System.Web.UI.HtmlControls.HtmlInputFile HIF in hif) 83 { 84 try 85 { 86 string fn = System.IO.Path.GetFileName(HIF.PostedFile.FileName); 87 HIF.PostedFile.SaveAs(baseLocation + fn); 88 filesUploaded++; 89 status += fn + "<br>"; 90 } 91 catch (Exception err) 92 { 93 TipInfo.Text = "上传错误 " + baseLocation 94 + "<br>" + err.ToString(); 95 } 96 } 97 98 if (filesUploaded == hif.Count) 99 { 100 TipInfo.Text = "共上传了 " + filesUploaded + " 个文件。 <br>" + status; 101 } 102 hif.Clear(); 103 FileList.Items.Clear(); 104 } 105 106 } 107 } 108} 109
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:51aspx多文件上传示例源码
51Aspx.com 版权所有 CopyRight © 2006-2010. 京ICP备06046876号 本站法律顾问:ITlaw-庄毅雄律师
返回顶部
客户服务:点击这里进行客户咨询 业务合作:点击这里洽谈业务合作 合作热线:010-68880146