解决方案 »

  1.   

    贴出你的 Content-disposition、ContentType 这两个信息。可能是后一个错了。
      

  2.   

    try
               {
               HttpContext.Current.Response.ContentType = "text/html";
               string filename = path.Substring(path.LastIndexOf("/")+1);
               HttpContext.Current.Response.AddHeader("Content-Disposition","attachment;filename="+filename);
               //**指定编码,防止中文文件名乱码
               HttpContext.Current.Response.HeaderEncoding = System.Text.Encoding.GetEncoding("gb2312");
               HttpContext.Current.Response.TransmitFile(path);
               }
               catch{throw;}
      

  3.   

    ContentType  不要设置成网页类型。
      

  4.   


    这个你真的应该自己去了解一下啊。我不负责帮写作业的哦。其实设置成别的什么(哪怕是错的),也一样解决你的问题的。例如application/vnd.android.package-archive
    video/x-msvideo
    application/msword
    application/msword
    video/x-flv
    image/gif
    image/x-icon
    application/vnd.ios.package-archive
    image/jpeg
    image/jpeg
    pplication/javascript
    image/png
    text/plain
    application/vnd.ms-powerpoint
    application/vnd.ms-powerpoint
    application/vnd.ms-powerpoint
    application/vnd.ms-powerpoint
    application/vnd.openxmlformats-officedocument.presentationml.presentation
    application/vnd.openxmlformats-officedocument.presentationml.template
    application/vnd.openxmlformats-officedocument.presentationml.slideshow
    application/vnd.ms-powerpoint.addin.macroEnabled.12
    application/vnd.ms-powerpoint.presentation.macroEnabled.12
    application/vnd.ms-powerpoint.presentation.macroEnabled.12
    application/vnd.ms-powerpoint.slideshow.macroEnabled.12
    application/x-silverlight-app
    application/vnd.ms-excel
    application/vnd.ms-excel
    application/vnd.ms-excel
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
    application/vnd.openxmlformats-officedocument.spreadsheetml.template
    application/vnd.ms-excel.sheet.macroEnabled.12
    application/vnd.ms-excel.template.macroEnabled.12
    application/vnd.ms-excel.addin.macroEnabled.12
    application/vnd.ms-excel.sheet.binary.macroEnabled.12任选一个你认为接近的好了。实在不知道,就写 application/octet-stream。
      

  5.   


    这个你真的应该自己去了解一下啊。我不负责帮写作业的哦。其实设置成别的什么(哪怕是错的),也一样解决你的问题的。例如application/vnd.android.package-archive
    video/x-msvideo
    application/msword
    application/msword
    video/x-flv
    image/gif
    image/x-icon
    application/vnd.ios.package-archive
    image/jpeg
    image/jpeg
    pplication/javascript
    image/png
    text/plain
    application/vnd.ms-powerpoint
    application/vnd.ms-powerpoint
    application/vnd.ms-powerpoint
    application/vnd.ms-powerpoint
    application/vnd.openxmlformats-officedocument.presentationml.presentation
    application/vnd.openxmlformats-officedocument.presentationml.template
    application/vnd.openxmlformats-officedocument.presentationml.slideshow
    application/vnd.ms-powerpoint.addin.macroEnabled.12
    application/vnd.ms-powerpoint.presentation.macroEnabled.12
    application/vnd.ms-powerpoint.presentation.macroEnabled.12
    application/vnd.ms-powerpoint.slideshow.macroEnabled.12
    application/x-silverlight-app
    application/vnd.ms-excel
    application/vnd.ms-excel
    application/vnd.ms-excel
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
    application/vnd.openxmlformats-officedocument.spreadsheetml.template
    application/vnd.ms-excel.sheet.macroEnabled.12
    application/vnd.ms-excel.template.macroEnabled.12
    application/vnd.ms-excel.addin.macroEnabled.12
    application/vnd.ms-excel.sheet.binary.macroEnabled.12任选一个你认为接近的好了。实在不知道,就写 application/octet-stream。
    好的.thanks..
      

  6.   

    我需要下载jpg 和 psd 两种格式文件..
    ContentType 设置成这个 application/octet-stream  后 
    本来应该是a.jpg 但是变成了a.html了。。
      

  7.   

    .Net对指定文件下载示例
    //引入命名空间
    using System.IO;
    //加载自定义方法
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)//首次加载
            {
                addListBox();   //调用用户自定义的addListBox方法            
            }
        }
    //自定义方法绑定控件
    protected void addListBox()
        {
            //将指定文件夹中的文件保存到字符串数组中
            string[] name = Directory.GetFiles(Server.MapPath("File"));
            foreach (string s in name)
            {
                //将文件名添加到ListBox中
                LisBoxFile.Items.Add(Path.GetFileName(s));
            }     
        }
    //把控件赋值给变量
    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["txt"] = LisBoxFile.SelectedValue.ToString();//从ListBox控件中选择的项赋值给Session["txt"]中
        }
    //获取下载路径下载文件
     protected void dFile()
        {
            //判断是否选择文件名
            if (LisBoxFile.SelectedValue != "")
            {
                if (Session["txt"] != "")
                {   //获取文件路径
                    string path = Server.MapPath("File/") + Session["txt"].ToString();
                    //初始化 FileInfo 类的实例,它作为文件路径的包装
                    FileInfo fi = new FileInfo(path);
                    
                    //判断文件是否存在
                    if (fi.Exists)
                    {
                        //将文件保存到本机上
                        Response.Clear();
                        Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fi.Name));
                        Response.AddHeader("Content-Length", fi.Length.ToString());
                        Response.ContentType = "application/octet-stream";
                        Response.Filter.Close();
                        Response.WriteFile(fi.FullName);
                        Response.End();
                    }
                }//CodeGo.net/
            }
            else
            {
                Page.RegisterStartupScript("sb", "<script>alert('请您先选择文件名')</script>");
            }
        }
    //把需要下载的文件保存到本地磁盘
      protected void ImgBtnDownFile_Click(object sender, ImageClickEventArgs e)
        {
           dFile();//调用用户自定义的dFile方法,实现
        }
    //断点续传跳转页面(略)