zoukankan      html  css  js  c++  java
  • 下载文件c#

    public void getDown(string filename)    //文件名
        {
            string destFileName = Server.MapPath("~/") + filename;  //文件路径
            destFileName = Server.UrlDecode(destFileName);
            Response.Write(destFileName);
            if (File.Exists(destFileName))
            {
                FileInfo fi = new FileInfo(destFileName);
                Response.Clear();
                Response.ClearHeaders();
                Response.Buffer = false;
                Response.AppendHeader("Content-Disposition", "attachment;filename="
                    + HttpUtility.UrlEncode(Path.GetFileName(destFileName), System.Text.Encoding.UTF8));
                Response.AppendHeader("Content-Length", fi.Length.ToString());
                Response.ContentType = "application/octet-stream";
                Response.WriteFile(destFileName);
                Response.Flush();
                Response.End();
            }
            else
            {
                Response.Write("<script langauge=javascript>alert('文件不存在!');history.go(-1);</script>");
                Response.End();
            }
        }
  • 相关阅读:
    爬虫header和cookie
    爬虫代理squid
    response对象
    pyspider中内容选择器常用方法汇总
    非阻塞 sleep
    post请求体过大导致ngx.req.get_post_args()取不到参数体的问题
    常用lua代码块
    nginx静态文件缓存的解决方案
    lua-resty-gearman模块
    非在线PDF转图片!!!
  • 原文地址:https://www.cnblogs.com/lfzwenzhu/p/1749508.html
Copyright © 2011-2022 走看看