<a href="~/down/文件.rar">下载<a>这段代码可以下载除.doc .txt这种系统不能识别的文件
问题是如果要下载的文件是.doc .txt这类文件直接就会被打开 怎么办啊

解决方案 »

  1.   

     用这个 或者按楼上的    
    /// <summary>
           /// 下载文件
           /// </summary>
           /// <param name="path">文件路径</param>
           public static void DownLoad(string path)
           {
                System.IO.FileInfo fi = new System.IO.FileInfo(path);
               HttpContext.Current.Response.Clear();
               HttpContext.Current.Response.ClearHeaders();
               HttpContext.Current.Response.Buffer = false;           HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(path)));
               HttpContext.Current.Response.AppendHeader("Content-Length", fi.Length.ToString());
               HttpContext.Current.Response.ContentType = "application/octet-stream";
               HttpContext.Current.Response.WriteFile(path);
               HttpContext.Current.Response.Flush();
               HttpContext.Current.Response.End();
            
           }
      

  2.   

    推荐个好的学习网站
    http://www.it63.net一起去学习学习
      

  3.   

    没有这种情况吧   假设你的文件叫  123.doc  放在工程的down 下面  那么你在运行的时候浏览器的地址改成这个下面的文件  出现的是一个下载页面!  localhost:端口号/项目名/down/123.doc