• 多文档上传功能实现


    .aspx
    <script type="text/javascript">
     function addfile()
     {
     var str='<INPUT id="upfile1" type="file" size="24" name="upfile1" style="BORDER-RIGHT: dimgray 1px solid; BORDER-TOP: dimgray 1px solid; BORDER-LEFT: dimgray 1px solid; WIDTH: 264px; BORDER-BOTTOM: dimgray 1px solid;"><br>'
     document.getElementById('myfile1').insertAdjacentHTML("beforeEnd",str)   
     }  
    </script>
     
    <table width="500" align="center">
         <tr>
               <td valign="top" width="120">
                     <asp:Label ID="lblselect" runat="server" Text="请选择文件路径"></asp:Label>
               </td>
               <td width="266">
                     <p id="myfile1">
                     <input id="upfile1" style="BORDER-RIGHT: dimgray 1px solid; BORDER-TOP: dimgray 1px solid; BORDER-LEFT: dimgray 1px solid; WIDTH: 264px; BORDER-BOTTOM: dimgray 1px solid; "  type="file" size="24" name="upfile4" runat="server">
                     </P> 
                </td>
                <td valign="top">
                     <input style="BORDER-RIGHT: 1px ridge; BORDER-TOP: 1px ridge; BORDER-LEFT: 1px ridge; WIDTH: 75px; BORDER-BOTTOM: 1px ridge; HEIGHT: 20px"  onclick="addfile()" type="button" size="14" value="New Control">                            
                </td>
         </tr>
         <tr>
                <td></td>
                <td>
                     <asp:Button ID="btnload" runat="server" Height="22px" Text="导入系统"  Width="64px" onclick="btnload_Click" />
                     <asp:Button ID="Btncancel" runat="server" Height="22px" Text="取  消" />
                     <asp:Button ID="Btnclose" runat="server" Height="22px" Text="关  闭" onclick="Btnclose_Click" />
                </td>
                <td></td>
         </tr>
    </table>
     
    .cs
    protected void Load_File()
    {
            HttpFileCollection files = HttpContext.Current.Request.Files;
            try
            {
                for (int iFile = 0; iFile < files.Count; iFile++)
                {
                    HttpPostedFile postedFile = files[iFile];
                    string filename, strServerFileName;//, fileExtension;
                    filename = System.IO.Path.GetFileName(postedFile.FileName);
                    if (filename != "")
                    {
                        //fileExtension = System.IO.Path.GetExtension(filename);获取filename文件扩展名                   
                        strServerFileName =System.IO.Path.GetDirectoryName(Server.MapPath("login.aspx")) + "\\Bom\\" + filename;
                        //将WebForm1.aspx所在的文件目录\上传的文件名赋给strServerFileName变量
                        postedFile.SaveAs(strServerFileName);//保存上载文件的内容                   
                        ReadExcel(strServerFileName, GridView1);
                    }
                }
                this.RefreshOpener();
            }
            catch (Exception ex)
            {
                lblmsg.Text = ex.Message;
                return;
            }
        }
  • 相关阅读:
    IOS快速集成下拉上拉刷新
    无限互联IOS电影项目视频笔记
    Unix时间戳(Unix timestamp)转换工具
    ***php(codeigniter)中如何重定向
    CodeIgniter 错误: In order to use the Session class you are required to set an encryption key
    一个Form中2个按钮,PHP后台如何判断提交的是哪一个按钮
    PHP 判断是否包含某字符串
    Linux那些事儿之我是Hub(大结局)挂起自动化【转】
    Linux USB Host-Controller的初始化代码框架分析【转】
    urb传输的代码分析【转】
  • 原文地址:https://www.cnblogs.com/lovewife/p/1396475.html
Copyright © 2020-2023  润新知