Asp.net C# 如何实现 多文件 多文件上传

jason20002001 2009-04-25 09:04:16
Asp.net C# 如何实现 多文件 多文件上传
...全文
64 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
蓝海D鱼 2009-04-25
  • 打赏
  • 举报
回复
多文件上传



Code
private void upMorefile()
{

HttpFileCollection files = Request.Files;

System.Text.StringBuilder strMsg = new System.Text.StringBuilder("上传的文件信息分别为:<hr color=red>");
int fileCount;

try
{
for (fileCount = 0; fileCount < files.Count; fileCount++)
{

HttpPostedFile postedFile = files[fileCount];
string fileName, fileExtension;

fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != String.Empty)
{

fileExtension = System.IO.Path.GetExtension(fileName);

strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
strMsg.Append("上传文件的文件名:" + fileName + "<br>");
strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr color=red>");


postedFile.SaveAs(Server.MapPath("upedFile/") + fileName);
}
}
strStatus.Text = strMsg.ToString();

}
catch (System.Exception error)
{
strStatus.Text = error.Message;
}
}
protected void Upload_Click(object sender, EventArgs e)
{
upMorefile();
}






Code
<head id="Head1" runat="server">
<title></title>
<script language="JavaScript">
function addFileControl() {
var str = '<INPUT type="file" NAME="File">'
document.getElementById('FileCollection').insertAdjacentHTML("beforeEnd", str)
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="upMoreFile" method="post" encType="multipart/form-data" runat="server">
<asp:label id="Title" Runat="server"></asp:label>
<P id="FileCollection"><INPUT type="file" name="File">
</P>
<P><input onclick="addFileControl()" type="button" value="增加(File)">
<asp:button id="Upload" Runat="server" Text="上传" Width="56px" OnClick="Upload_Click"></asp:button>
<input style="WIDTH: 56px; HEIGHT: 24px" onclick="this.form.reset()" type="button" value="重置">
</P>
<p>
<asp:label id="strStatus" runat="server" BorderColor="White" BorderStyle="None" Width="544px"
Font-Size="9pt" Font-Bold="True" Font-Names="宋体"></asp:label> </p>
</form>
</body>

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧