zoukankan      html  css  js  c++  java
  • .net利用iframe,不刷新上传文件

    HTML
    重点在于:

    1. target="iframe1"
    2. enctype="multipart/form-data"
    3. method="post"
     1 <form id="form1" runat="server" target="iframe1" enctype="multipart/form-data" method="post">
     2         <div>
     3             <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
     4         </div>
     5         <div>
     6             <input id="File1" type="file" runat="server" />
     7             <input id="File2" type="file" runat="server" />
     8             <input id="File3" type="file" runat="server" />
     9             <input id="File4" type="file" runat="server" />
    10 
    11             <asp:Button ID="btn_save" runat="server" Text="上传" OnClick="btn_save_Click" Width="63px" />
    12             <asp:Label ID="lbl_message" runat="server" Font-Names="方正姚体" Font-Size="9pt" ForeColor="Red"></asp:Label>
    13         </div>
    14     </form>
    15     <iframe id="iframe1" name="iframe1" style=" 0px; height: 0px; border: none"></iframe>

    后台

     1 protected void btn_save_Click(object sender, EventArgs e)
     2         {
     3             try
     4             {
     5                 //1.自带保存
     6                 for (int i = 0; i < this.Request.Files.Count; i++)
     7                 {
     8                     if (this.Request.Files[i].FileName == "")
     9                     {
    10                         continue;
    11                     }
    12 
    13                     string fileName = this.Request.Files[i].FileName.Substring(this.Request.Files[i].FileName.LastIndexOf('\') + 1);
    14                 
    15                     this.Request.Files[i].SaveAs(Server.MapPath("Files/" + fileName));
    16                 }
    17 
    18                 this.Response.Write("<script>alert('保存成功')</script>");
    19 
    20 
    21                 //2.文件流保存
    22                 //string fileName = this.Request.Files[0].FileName.Substring(this.Request.Files[0].FileName.LastIndexOf('\') + 1);
    23                 //System.IO.Stream fsInput = this.Request.Files[0].InputStream;
    24                 //FileStream fs = File.OpenWrite(Server.MapPath("Files/" + fileName));
    25                 //fsInput.CopyTo(fs, 1024);
    26                 //fsInput.Flush();
    27                 //fsInput.Close();
    28                 //fs.Flush();
    29                 //fs.Close();
    30             }
    31             catch (Exception ex)
    32             {
    33                 string a = ex.Message;
    34             }
    35 
    36         }
  • 相关阅读:
    Windows Server2012R2 添加Microsoft .NET Framework 3.5 功能失败的解决方法
    Windows Server2012R2 安装 SharePoint 2013 的必备组件
    pig加载两个不同字段个数的文件?load file with different items(f1有42列,f2有43列读到一个对象中)
    正则表达式的子模式详解
    PHP 递归函数的理解
    仿照美食杰tab选项卡
    tab简单选项卡
    PHP字符串变驼峰方法
    PHP笔试题
    PHP面试题集
  • 原文地址:https://www.cnblogs.com/loge/p/9975852.html
Copyright © 2011-2022 走看看