zoukankan      html  css  js  c++  java
  • ASP.NET 对于文件的下载与上传

     /// <summary>
            /// 下载附件查看
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void downButton_Command(object sender, CommandEventArgs e)
            {
    //传递过来的参数
    string fullName = e.CommandArgument.ToString(); string fileName=System.IO.Path.GetFileName(fullName); if (!string.IsNullOrEmpty(fullName)) { try { System.IO.FileInfo downloadFile = new System.IO.FileInfo(fullName); if (downloadFile.Exists) { Response.Clear(); Response.ClearHeaders(); Response.Buffer = false; Response.ContentType = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); Response.AppendHeader("Content-Length", downloadFile.Length.ToString()); Response.WriteFile(downloadFile.FullName); Response.Flush(); Response.End(); } else { ClientScript.RegisterStartupScript(this.GetType(), "", "alert('不存在这个链接')",true); } } catch { ClientScript.RegisterStartupScript(this.GetType(), "", "alert('操作失败')", true); } } }


     //文件的上传
     protected void appSubmit_Click(object sender, EventArgs e)
            {
                FileUpload upFile = (FileUpload)this.DVSalary.FindControl("appFileUpload");
                if (upFile.HasFile)
                {
                    string staffId = ((Label)(this.DVSalary.FindControl("staffID"))).Text.Trim();
                    string fileName = "";
                    string[] strings = upFile.FileName.Split('\');
                    string[] docNames = strings[strings.Length - 1].Split('.');
                    string docName = staffId + DateTime.Now.Year
                        + DateTime.Now.Month + DateTime.Now.DayOfYear 
                        + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second 
                        + DateTime.Now.Millisecond 
                        + "."
                        + docNames[docNames.Length - 1];
                    fileName = "D:\" + docName;
                    upFile.SaveAs(fileName);
                    //保存上传的附件名
                    Session["file"] = fileName;
                    Label tip = (Label)this.DVSalary.FindControl("toolTip");
                    tip.Visible = true;
                    tip.ForeColor = System.Drawing.Color.Red;
                    tip.Text = "文件上传成功";
                    
                }
            }
    
    
    
     
  • 相关阅读:
    sql server 2008安装要求
    当您尝试再次安装 SQL Server 时,SQL Server 2008年安装将会失败
    SQL Server数据库附加失败:错误5120和错误950
    sql server数据库数据查询成功
    MYSQL数据库连接
    解决java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver问题
    JSP数据库连接成功
    SQLServerException:通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。
    win10中打开SQL Server配置管理器方法
    XHTML XML
  • 原文地址:https://www.cnblogs.com/aswater-yuanye/p/3534982.html
Copyright © 2011-2022 走看看