asp.net多次上传与多个FileUpload控件 [英] asp.net multiple uploads with multiple fileupload control
本文介绍了asp.net多次上传与多个FileUpload控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的工作在狭小的项目,处理多个文件上传。
I'm working in tiny project that deal with multiple file uploading.
在开始时用户拥有的一个FileUpload控件和小图片名为 fileuploadadder
at the begining user have one fileupload control and a small image called fileuploadadder .
每次上fileuploadadder,一个克隆在第一次文件上传的用户点击控件添加到页面的的jQuery 。在 IDS 的文件上传控件是潮头。如文件1,文件2,...
each time user click on fileuploadadder , a clone of the first fileupload control added to the page with jquery . the ids of the fileupload controls are uniqe. such as file1 , file2, ...
现在,我想,当用户点击页面asp.net的最后一个按钮,上传选定的文件。
now , i want when user clicks on a button at the end of the page asp.net uploads the selected files.
TNX
推荐答案
下面是一个例子:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<script type="text/c#" runat="server">
protected void BtnUpload_Click(object sender, EventArgs e)
{
if (Request.Files != null)
{
foreach (string file in Request.Files)
{
var uploadedFile = Request.Files[file];
if (uploadedFile.ContentLength > 0)
{
var appData = Server.MapPath("~/app_data");
var fileName = Path.GetFileName(uploadedFile.FileName);
uploadedFile.SaveAs(Path.Combine(appData, fileName));
}
}
}
}
</script>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form id="Form1" runat="server" enctype="multipart/form-data">
<a href="#" id="add">Add file</a>
<div id="files"></div>
<asp:LinkButton ID="BtnUpload" runat="server" Text="Upload" OnClick="BtnUpload_Click" />
</form>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$('#add').click(function () {
$('#files').append($('<input/>', {
type: 'file',
name: 'file' + new Date().getTime()
}));
return false;
});
</script>
</body>
</html>
这篇关于asp.net多次上传与多个FileUpload控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文