zoukankan      html  css  js  c++  java
  • HTML <input type="file">结合asp.net的一个文件上传示例

    HTML的代码:(关键是要在form里设置enctype="multipart/form-data",这样才能在提交表单时,将文件以二进制流的形式传输到服务器)

        <form id="form1" runat="server"  method="post" enctype="multipart/form-data">
        <div>
        <input type="file" />
         <asp:Button ID="btnUpload" runat="server"  Text="开始上传" onclick="btnUpload_Click" />
        </div>
        </form>

    aps.net后台代码(C#):

            protected void btnUpload_Click(object sender, EventArgs e)
            {
                //int intCount = RequestClass.GetFormInt("hdcount", -1);
                HttpFileCollection Files = HttpContext.Current.Request.Files;
                for (int i = 0; i < Files.Count; i++)
                {
                    HttpPostedFile PostedFile = Files[i];
                    if (PostedFile.ContentLength > 0)
                    {
                        string FileName = PostedFile.FileName;
                        string strExPrentFile = FileName.Substring(FileName.LastIndexOf(".") + 1);
    
                        string sFilePath = "/uploadfile/hotel/" + StringClass.makeFileName24() + i + strExPrentFile;
                        PostedFile.SaveAs(Server.MapPath(sFilePath));
                    }
                    else
                    {
                        //this.LabMessage.Text = "不能上传空文件";
                    }
                }
            }
  • 相关阅读:
    UVALive4727:jump
    UVALive
    UVA11795 Mega Man's Mission
    UVA4731:Cellular Network
    UVA11404:Palindromic Subsequence
    设计思路
    阅读计划
    上课未完成代码原因
    《人月神话》读后感
    《软件工程》第十一章总结
  • 原文地址:https://www.cnblogs.com/fumj/p/2817769.html
Copyright © 2011-2022 走看看