<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
一、上传界面内容
选择文件: |
选择文件: |
说明:为了能正确显示,把原有asp.NET按钮控件换成了HTML的按钮控件
二、后台代码
1.page_load部分内容
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
UpLoadHelper helper = new UpLoadHelper();
helper.RegisterProgressBar(bt_save.UniqueID);
string path = Path.Combine(Server.MapPath("."),"loadfile");
if(!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
helper.UploadFolder = path;
bind();
}
2.加入了自定义的显示上传文件夹的文件列表方法
public void bind()
{
string path = Path.Combine(Server.MapPath("."),"loadfile");
if(!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
Table1.Rows.Clear();
foreach(string filename in Directory.GetFiles(path))
{
TableRow r = new TableRow();
TableCell c = new TableCell();
c.Text = filename;
r.Cells.Add(c);
Table1.Rows.Add(r);
}
}
3.批量上传文件的代码
UpLoadHelper helper = new UpLoadHelper();
string path = Path.Combine(Server.MapPath("."),"loadfile");
foreach(UpLoadFile file in helper.GetUploadFileList("file1"))
{
file.SaveAs(Path.Combine(path,Path.GetFileName(file.FileName)));
}
bind();
4.单个文件上传的代码
UpLoadHelper helper = new UpLoadHelper();
string path = Path.Combine(Server.MapPath("."),"loadfile");
UpLoadFile file = helper.GetUploadFile("s_file");
file.SaveAs(Path.Combine(path,Path.GetFileName(file.FileName)));
bind();
三、说明