zoukankan      html  css  js  c++  java
  • ASP.NET下载文件 . 天高地厚

    using System.IO;
        'FilePath - Refers to Full Path of the file
            protected void DownloadFile(string FilePath)
            {
                // Gets the File Name
                string fileName = FilePath.Substring(FilePath.LastIndexOf('\\') + 1);
                byte[] buffer;

                using (FileStream fileStream = new FileStream(FilePath, FileMode.Open))
                {
                    int fileSize = (int)fileStream.Length;
                    buffer = new byte[fileSize];
                    // Read file into buffer
                    fileStream.Read(buffer, 0, (int)fileSize);
                }
                Response.Clear();
                Response.Buffer = true;
                Response.BufferOutput = true;
                Response.ContentType = "application/x-download";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
                Response.CacheControl = "public";
                // writes buffer to OutputStream
                Response.OutputStream.Write(buffer, 0, buffer.Length);
                Response.End();
            }

  • 相关阅读:
    WPF 模板(二)
    WPF 模板
    WFP 样式(复习用)
    wpf 特效学习
    MVC 开源控件学习
    设计模式学习
    使用带参数方式新增或修改可为空的非字符串类型数据到oralce数据库
    python(13)- 文件处理应用Ⅱ:增删改查
    051孤荷凌寒从零开始学区块链第51天DAPP006
    050孤荷凌寒从零开始学区块链第50天DAPP003
  • 原文地址:https://www.cnblogs.com/net2012/p/2886308.html
Copyright © 2011-2022 走看看