zoukankan      html  css  js  c++  java
  • 后台下载

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.IO;
    
    public partial class customer_detail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FileDownload();
        }
    
        private void FileDownload()
        {
            int id = 0;
            if (Request.QueryString["id"] != null)
            {
                int.TryParse(Request.QueryString["id"].ToString(), out id);
            }
            if (id > 0)
            {
                BLL.DownLoad dlBll = new BLL.DownLoad();
                Model.DownLoad m = dlBll.GetModelBystrWhere("ID=" + id);
                if (m != null && System.IO.File.Exists(Server.MapPath(m.Information)))
                {
                    Model.DownLoad model = new Model.DownLoad();
                    model.num = m.num + 1;
                    dlBll.Update(model, "ID=" + id);
                    FileInfo file = new FileInfo(Server.MapPath(m.Information));
                    Response.Clear();
                    Response.ClearHeaders();
                    Response.Buffer = false;
                    Response.ContentType = "application/octet-stream";
                    Response.AppendHeader("Content-Disposition", "attachment;filename="
                        + HttpUtility.UrlEncode(m.Information, System.Text.Encoding.UTF8));
                    Response.AppendHeader("Content-Length", file.Length.ToString());
                    Response.WriteFile(file.FullName);
                    Response.Flush();
                    Response.End();
                    Response.Write("down");
                }
                else
                {
                    Error("文件未找到");
                }
            }
            else
            {
                Error("请求参数错误");
            }
        }
        public void Error(string msg)
        {
            Response.Write(msg);
        }
    }
  • 相关阅读:
    周记(2015-11-30 -- 2015-12-05)
    周记(2015-11-22 -- 2015-11-27)
    周记(2015-11-15 -- 2015-11-20)
    周记(2015-11-01 -- 2015-11-06)
    设备与主机的攻击日志类型分析总结
    OWASP十大攻击类型详解
    乌云TOP 10 简单介绍
    《启示录》读书笔记三
    百度地图和定位
    获取Android studio的SHA1值
  • 原文地址:https://www.cnblogs.com/daixingqing/p/2768328.html
Copyright © 2011-2022 走看看