惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
Blog — PlanetScale
Blog — PlanetScale
Vercel News
Vercel News
L
LangChain Blog
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
About on SuperTechFans
博客园_首页
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
美团技术团队
V
V2EX

博客园 - 大牛博客

广东早茶的悠闲时光 用户中心 - 博客园 GridView数据绑定控件和ObjectDataSource数据源控件实现排序功能 - 大牛博客 - 博客园 asp.net 常用字符串过滤方法 非常实用的Asp.net常用的51个代码 - 大牛博客 - 博客园 JS 中面向对象的5钟写法 GridView的RowCommand事件中取得行索引 - 大牛博客 - 博客园 .netframework3.5 中TimeZoneInfo 类的使用 GridView,DataList,Repeater,DetailsView的遍历行代码 - 大牛博客 - 博客园 ASP.NET 2.0上传图片生成缩略图类 合理选择贪婪模式与非贪婪模式 - 大牛博客 - 博客园 揭开正则表达式的神秘面纱 C#数据结构之双向链表 C#数据结构之队列 ASP.NET四种页面导航方式之比较与选择 asp.net页面事件执行顺序 中英文字符串截取方法 - 大牛博客 - 博客园 ASP.NET纯数字验证码 SQL 2005 ROW_NUMBER() 语句分页 | SQL效率最高的分页查询数据
asp.net下载文件 - 大牛博客 - 博客园
大牛博客 · 2009-07-14 · via 博客园 - 大牛博客

/// <summary>
    /// 下载文件
    /// </summary>
    /// <param name="vPath">文件路径(绝对路径)</param>
    public static void DownloadData(string path)
    {
        if (File.Exists(path))
        {
            FileInfo DownloadFile = new FileInfo(path);
            System.Web.HttpContext.Current.Response.Clear();
            System.Web.HttpContext.Current.Response.ClearHeaders();
            System.Web.HttpContext.Current.Response.Buffer = false;
            System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
            System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
            System.Web.HttpContext.Current.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
            System.Web.HttpContext.Current.Response.WriteFile(DownloadFile.FullName);
            System.Web.HttpContext.Current.Response.Flush();
            System.Web.HttpContext.Current.Response.End();
        }
        else
        {
            throw new Exception("提示:下载失败,找不到该文件");
        }
    }