All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET,利用Outlook发送邮件_[Asp.Net教程]
关于XHTML头部声明,什么是DOCTYPE?_[Html教程]
GridView中添加CheckBox并返回选中行_[Asp.Net教程]
Web服务数据库访问中间件的实现_.net资料_编程技术
SQL数据库高级教程:SQL CREATE VIEW 语句_[SQL Server教程]
配置Apache2+PHP5+MYSQL5_[PHP教程]
学习SQL2005当中的例子_mssql学习_编程技术
C#教程:C#中的赋值运算符
ASP.NET2.0数据操作之创建业务逻辑层_[Asp.Net教程]
visual c++类中的友元函数
Reading number is top 10 pictures
9.3阅兵全景图1-抗战老兵和英雄连队梯队
Li Zongrui hunting video screenshots2
新版武松打虎
A beautiful girl to bud1
From China fortress sora aoi1
刘亦菲写真集2
心有鱼而力不足
Beautiful vacuum girl1
The real super beauty9
Hunan province aizhai super-large suspension bridge open to traffic and 4 world first2
Download software ranking
好色的外科大夫
卡丁车单机版
linux高级编程
实战黑客不求人
SP3 for SQL2000
Tram sex maniac 2 (H) rar bag1
Eclipse 4.2.2 For Win32
Visual C++界面编程技术
Adobe Flash Player(IE) 10.0.32.18 浏览器专用的FLASH插件
传奇私服架设教程
delv published in(发表于) 2014/1/24 9:07:46 Edit(编辑)
ASP.NET实例:多文件上传源码_[Asp.Net教程]

ASP.NET实例:多文件上传源码_[Asp.Net教程]

ASP.NET实例:多文件上传源码_[Asp.Net教程]

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.Collections;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)//首次执行页面
{
SFUPC();//页面执行一次将上传文件控件集到缓存中
}
}
protected void Button1_Click(object sender, EventArgs e)
{
UpFile();//执行上传文件
}
protected void Button2_Click(object sender, EventArgs e)
{
InsertC();//执行添加控件方法
}
private void SFUPC()//该方法用于保存当前页面上传文件控件集到缓存中
{
ArrayList AL = new ArrayList();//创建动态增加数组
foreach (Control C in F.Controls)
{
if (C.GetType().ToString() == "System.Web.UI.HtmlControls.HtmlTableRow")
{
HtmlTableCell HTC = (HtmlTableCell)C.Controls[0];
foreach (Control FUC in HTC.Controls)
{
if (FUC.GetType().ToString() == "System.Web.UI.WebControls.FileUpload")
{
FileUpload FU = (FileUpload)FUC;
AL.Add(FU);
}
}
}
}
Session.Add("FilesControls", AL);
}
private void InsertC()//该方法用于添加一个上传文件的控件
{
ArrayList AL = new ArrayList();
this.F.Rows.Clear();
GetInfo();
HtmlTableRow HTR = new HtmlTableRow();
HtmlTableCell HTC = new HtmlTableCell();
HTC.Controls.Add(new FileUpload());
HTR.Controls.Add(HTC);
F.Rows.Add(HTR);
SFUPC();
}
private void GetInfo()//该方法用于读取缓存中存储的上传文件控件集
{
ArrayList AL = new ArrayList();
if (Session["FilesControls"] != null)
{
AL = (System.Collections.ArrayList)Session["FilesControls"];
for (int i = 0; i < AL.Count; i++)
{
HtmlTableRow HTR = new HtmlTableRow();
HtmlTableCell HTC = new HtmlTableCell();
HTC.Controls.Add((System.Web.UI.WebControls.FileUpload)AL[i]);
HTR.Controls.Add(HTC);
F.Rows.Add(HTR);
}
}
}
private void UpFile()//该方法用于执行文件上传操作
{
string FilePath = Server.MapPath("./") + "File";
HttpFileCollection HFC = Request.Files;
for (int i = 0; i < HFC.Count; i++)
{
HttpPostedFile UserHPF = HFC[i];
try
{
if (UserHPF.ContentLength > 0)
{
UserHPF.SaveAs(FilePath + "\\" + System.IO.Path.GetFileName(UserHPF.FileName));
Label1.Text = "上传成功!";
}
else
{
Label1.Text = "处理出错!文件不能为空";
}


}
catch
{
Label1.Text = "处理出错!";
}


}
if (Session["FilesControls"] != null)
{
Session.Remove("FilesControls");
}

}
}








添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.