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,浏览器会拦截弹出窗口

     

  • 相关阅读:
    css03层次选择器
    css02基本选择器
    Distance Between Points
    CloseHandle(IntPtr handle)抛异常
    关于win7上内存占用较大的说明
    C# WPF 显示图片和视频显示 EmuguCv、AForge.Net测试(续)
    五种开源协议的比较(BSD_Apache_GPL_LGPL_MIT)
    C# WPF 显示图片和视频显示 EmuguCv、AForge.Net测试
    Opencv不用每次创建项目配置vs2010 vc++目录 库目录等项
    矩阵运算
  • 原文地址:https://www.cnblogs.com/dashi/p/4034670.html
Copyright © 2011-2022 走看看