zoukankan      html  css  js  c++  java
  • 下载附件代码

      Response.Clear();
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.ContentType = "application/octet-stream ; Charset=UTF8";
                    Response.CacheControl = "public";
                   
                    string realFileName = fileName.IndexOf('_') > 0 ? fileName.Remove(0, fileName.IndexOf('_') + 1) : fileName;
                    Response.AddHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode(realFileName, System.Text.Encoding.GetEncoding("UTF-8")) + "\"");
                    Response.AddHeader("Content-Length", fileSize.ToString());
                    Response.AddHeader("Content-Transfer-Encoding", "binary");
                    Response.Filter.Close();

     #region
                   // int everySize =Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["EverySize"].ToString()); //每次读取配置文件中分块下载的大小
                   // byte[] buffers=new byte[everySize];
                   //// System.IO.FileStream istream = System.IO.File.OpenRead(fileInfo.FullName);
                   // using (System.IO.FileStream istream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
                   // {
                   //     long dataLenghtRead = istream.Length;
                   //     while (dataLenghtRead > 0 && Response.IsClientConnected)
                   //     {
                   //         int readLength = istream.Read(buffers, 0, everySize);
                   //         Response.OutputStream.Write(buffers, 0, readLength);
                   //         Response.Flush();
                   //         dataLenghtRead = dataLenghtRead - readLength;
                   //     }
                   // }
                   /////Response.WriteFile(fileInfo.FullName);
                   //istream.Close();
                   //istream.Dispose();
                    #endregion

  • 相关阅读:
    DP入门——迷宫行走方案2
    DP入门——迷宫行走方案1
    DFS入门——八皇后问题输出方案
    matplotlib的学习3-figure图像
    matplotlib的学习2-基本用法
    matplotlib的学习1-为什么学他
    numpy的好处
    pandas的学习8-pandas-plot出图
    pandas的学习6-合并concat
    pandas的学习5-导入导出数据
  • 原文地址:https://www.cnblogs.com/cxlings/p/2372794.html
Copyright © 2011-2022 走看看