多文件上传示例代码

Admin | 2007-10-11 13:39:06 | TrackRecord: 1439 Times | Tag标签:asp.net 打印本页

您当前所处的位置是:〖首页〗→【文章页】 本站共有16个图文教程栏目,请用心拜读!

本站提供经典的Excel公式函数实例,Word排版技巧,PPT教程;同时更兼有Flash,PowerPoint,数据库等技术文章。

<%@ Page Language="C#"%>
<%@ import namespace="System.IO"%>
<style>
body,input {font-size:12px;}
</style>
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
 
}
protected void Butupsure_Click(object sender, EventArgs e)
{
        //---在此获得上传文件的文件名----
  String savePath = Server.MapPath("upload");
  if( !Directory.Exists(savePath) )
  {
         Directory.CreateDirectory(savePath);
  }

  HttpFileCollection files  = HttpContext.Current.Request.Files;
  for(int iFile = 0; iFile < files.Count; iFile++)
  {
   HttpPostedFile postedFile = files[iFile];
      string fileName, fileExtension;
   fileName = System.IO.Path.GetFileName(postedFile.FileName);
   if (fileName != "")
   {
    fileExtension = System.IO.Path.GetExtension(fileName);
    
    postedFile.SaveAs(savePath + "\\" + fileName);

    Response.Write("<a href='upload/" + fileName + "' target=_blank>" + savePath + "\\" + fileName + "</a><br/>");
    TbMsg.Text +="<a href='upload/" + fileName + "' target=_blank>" + savePath + "\\" + fileName + "</a>\r\n";

    TbMsg.Text += "savePath=" + savePath + "\r\n";
    TbMsg.Text += "fileName=" + fileName + "\r\n";
   }
  }
  
}
</script>
<body>
<form id=form1 runat="server" ENCTYPE = "multipart/form-data">
<div id="upFiles">
</div>

<BR>上传数量:
<INPUT TYPE="text" NAME="Txtfilenum" id="Txtfilenum" value="5">
<input type="button" value="添加" onclick="Add();"/>
<script language="javascript">
function Add()
{
var up=document.getElementById ("upFiles");
var count =document.getElementById("Txtfilenum").value;
for(var i=0;i<count;i++)
{
var txt = document.createElement("input");
txt.type="file";
txt.id="fileup"+i;
txt.name = txt.id;
up.appendChild(txt);
up.appendChild(document.createElement("BR"));
}

}

</script>
<BR>
<asp:Button ID="Butupsure" runat="server" Text="上 传" OnClick="Butupsure_Click" />
<BR>
<asp:TextBox id="TbMsg" runat=server TextMode="MultiLine" width="500px" height="300px"></asp:TextBox>
</form>
</body>



上一篇:用SqlCommandBuilder 实现批量更新    下一篇:asp.net(c#)发送邮件代码

会员评论列表:
针对本篇文章或本站,请您发表个人的建议或批评!
FreeBoxPc

谷歌搜索 百度搜索 本站仅与内容具备一定的实用价值的原创网站交换友情链接,力争为大众做出更优质的服务!
All Rights Reserved版权所有 本站备案信息:滇ICP备11001339号-2 站长联系方式 Email:dzwebs@126.com