zoukankan      html  css  js  c++  java
  • 文件下载解决中文乱码

           string path = "需要下载的文件路径";

                   if (File.Exists(path))

                   {

                       if (!".zip.rar.".Contains(Path.GetExtension(path) + "."))

                       {

                           Response.Write("不允许此类文件的下载!");

                           return;

                       }

                       string name = Path.GetFileName(path);

                       if (string.IsNullOrEmpty(name))

                       {

                           name = new FileInfo(path).Name;

                       }

                       Response.Clear();

                       if (Request.Browser.Browser == "IE")

                       {

                          name= HttpUtility.UrlPathEncode(name);

                       }

        

                       Response.AddHeader("Content-Disposition",

                                          "attachment;filename=\"" +name + "\"");

                       byte[] buffer = File.ReadAllBytes(path);

                       Response.AddHeader("Content-Length", buffer.Length.ToString());

                       Response.ContentType = "application/zip;charset=utf-8";

                       Response.BinaryWrite(buffer);

     

                   }

                   else

                   {

                       Response.Write(string.Format("文件{0}不存在!", path));

                   }

     

    //另外需注意打开此页面时应使用window.location.href

    而不用window.open,浏览器会拦截弹出窗口

     

  • 相关阅读:
    【bzoj4987】Tree 树形dp
    【bzoj5093】 [Lydsy1711月赛]图的价值 组合数+斯特林数+NTT
    【BZOJ2159】Crash的文明世界 斯特林数+树形dp
    python enumerate函数同时遍历索引和函数
    gensim ——训练word2vec词向量的使用方法。
    moses工具的配置详解
    linux下boost库的安装
    python 调用word2vec
    python 默认编码
    GIZA++工具的使用介绍
  • 原文地址:https://www.cnblogs.com/dashi/p/4034670.html
Copyright © 2011-2022 走看看