当前位置:编程学习 > C#/ASP.NET >>

在chrome上怎么实现文件的下载?

在chrome上怎么实现文件的下载?我用window.open(url),<a href="url"></a>,都不能实现下载,都是打开,怎么办?求救!!! chrome 下载 --------------------编程问答-------------------- 文件什么格式的?

在IIS 上配置下 MIME 类型 应该就可以了。 --------------------编程问答-------------------- 音频,视频,图片,flash,要配置IIS? 那用户的机子上没有配置怎么办? --------------------编程问答--------------------

 public void downloadfile(string s_fileName)
    {
        HttpContext.Current.Response.ContentType = "application/ms-download";
        string s_path = HttpContext.Current.Server.MapPath("~/") + s_fileName;
        System.IO.FileInfo file = new System.IO.FileInfo(s_path);
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
        HttpContext.Current.Response.Charset = "utf-8";
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
        HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
        HttpContext.Current.Response.WriteFile(file.FullName);
        HttpContext.Current.Response.Flush();
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.End();
    }
--------------------编程问答--------------------
引用 2 楼 xiangdaoquan 的回复:
音频,视频,图片,flash,要配置IIS? 那用户的机子上没有配置怎么办?


对的 每一种类型(例如:*.mv,*.rmvb,*.wv) 都要配置 MIME 类型

IIS 配置了 就好下载了,客户不用配置。

参考
http://blog.csdn.net/csethcrm/article/details/7018417

里边没有的 可以百度搜一下


--------------------编程问答-------------------- 我是来顶的, --------------------编程问答--------------------
引用 4 楼 CsethCRM 的回复:
引用 2 楼 xiangdaoquan 的回复:音频,视频,图片,flash,要配置IIS? 那用户的机子上没有配置怎么办?

对的 每一种类型(例如:*.mv,*.rmvb,*.wv) 都要配置 MIME 类型

IIS 配置了 就好下载了,客户不用配置。

参考
http://blog.csdn.net/csethcrm/article/details/……

噢。谢了。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,