• 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();
            }

  • 相关阅读:
    SQL Server 的事务和锁(一)
    Sql server脏读、更新丢失、不可重复读、幻象读问题及解决方案
    Sql server锁机制
    Windows系统变量列表
    windows运行命令大全
    C# 捕获数据库自定义异常
    sql日期函数
    C# ado.net 操作存储过程(二)
    C# ado.net 操作(一)
    url传参特殊字符问题(+、%、#等)
  • 原文地址:https://www.cnblogs.com/net2012/p/2886308.html
Copyright © 2020-2023  润新知