转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 站长学院 >> Web开发 >> 正文
多文件上传示例代码         ★★★★

多文件上传示例代码

作者:闵涛 文章来源:闵涛的学习笔记 点击数:749 更新时间:2009/6/9 2:35:18

<%@ 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>


[C语言系列]C# DES 加密/解密,支持文件和中文/UNICODE字符,…  [办公软件]PowerPoint文件保存为PPS与PPT等格式的应用范围
[办公软件]提取PPT文件中的GIF动画(也可提取各种素材对象)  [办公软件]Word、Excel和PowerPoint文件格式兼容包(简体中文…
[办公软件]VBA设置文件属性及加密源代码示例  [办公软件](解除)破解Excel文件密码保护的方法与(解除)破解原…
[办公软件]无法打开Excel文件(*.xls)之最佳答案(工具选项配置…  [办公软件]如何设置Excel(*.xls)文件密码(给Excel文件加密)(…
[网络安全]网站存在上传漏洞被挂马的解决办法(供参考)  [Sql Server]SQL Server日志文件损坏的解决办法
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Web开发  · 网页制作
    · 平面设计  · 网站运营
    · 网站推广  · 搜索优化
    · 建站心得  · 站长故事
    · 互联动态
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台