请教:文件下载问题<a href="a.aaa">下载1</a>显示下载对话框,<a href="a.txt">下载2</a>直接显示文件内容,如何让下载2也显示下载对话框?
希望给出详细语句。
谢谢!

解决方案 »

  1.   

    .txt在浏览器上是可以打开的,你可以压缩成zip或rar文件就可以了
      

  2.   

    简单的改扩展名
    麻烦的
    Dim fileLocation As String
            fileLocation = ConfigurationSettings.AppSettings("ServerPlanSheetFolder") & lnkDownload.Text
            Response.Clear()
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("shift-jis")
            Response.AddHeader("Content-Disposition", "attachment; filename=" & lnkDownload.Text)
            Response.ContentType = "application/ms-excel"
            Response.WriteFile(fileLocation)
            Response.End()
      

  3.   

    if(File.Exists(paths))
                    {
                        FileInfo fi=new FileInfo(paths);
                        Response.Clear();
                        Response.ClearHeaders();
                        Response.Buffer=false;
                                                                  
                      //Response.AppendHeader("Content-Disposition","attachment;filename=" + System.Web.HttpUtility.UrlEncode(CheckStringLength(Path.GetFileName(paths)),System.Text.Encoding.Default));
                       Response.AppendHeader("Content-Disposition","attachment;filename=" + System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(CheckStringLength(Path.GetFileName(paths)))));
                       Response.AppendHeader("Content-Length",fi.Length.ToString());
                       // Response.AppendHeader("Content-Type",fi.Extension.ToString());
                        Response.ContentType="application/octet-stream";
                        Response.WriteFile(paths);
                        Response.Flush();
                        Response.End();
                    }
                    else
                    {
                        Response.Write("<script langauge=javascript>alert('The file does not exist!');history.go(-1);</script>");
                       // msg.msgs("The file does not exist.");return;
                    }
      

  4.   

    不用<a> 用一个命令按钮,执行下面的内容,会出现下载对话框string name=lb1.Text; string fullName=currentPath+name;

    FileInfo aFile=new FileInfo(fullName); Response.Clear();
    Response.ClearHeaders();
    Response.BufferOutput=false;
    Response.ContentType="application/octet-stream";
    Response.AppendHeader("Content-disposition","attachment;filename="+HttpUtility.UrlEncode(name,System.Text.Encoding.UTF8));
    Response.AppendHeader("Content-Length",aFile.Length.ToString());
    Response.WriteFile(fullName);
    Response.Flush();
    Response.End();
      

  5.   

    if(File.Exists(paths))
                    {
                        FileInfo fi=new FileInfo(paths);
                        Response.Clear();
                        Response.ClearHeaders();
                        Response.Buffer=false;
                                                                  
                      //Response.AppendHeader("Content-Disposition","attachment;filename=" + System.Web.HttpUtility.UrlEncode(CheckStringLength(Path.GetFileName(paths)),System.Text.Encoding.Default));
                       Response.AppendHeader("Content-Disposition","attachment;filename=" + System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(CheckStringLength(Path.GetFileName(paths)))));
                       Response.AppendHeader("Content-Length",fi.Length.ToString());
                       // Response.AppendHeader("Content-Type",fi.Extension.ToString());
                        Response.ContentType="application/octet-stream";
                        Response.WriteFile(paths);
                        Response.Flush();
                        Response.End();
                    }
                    else
                    {
                        Response.Write("<script langauge=javascript>alert('The file does not exist!');history.go(-1);</script>");
                       // msg.msgs("The file does not exist.");return;
                    }