LinkButton lkb = (LinkButton)sender;
        //获取事件按钮所在的行
        GridViewRow gvr = (GridViewRow)lkb.Parent.Parent;
        string fileName = (GridView1.Rows[gvr.RowIndex].Cells[1]).Text.ToString().Trim()+".txt";        string filePath = (GridView1.Rows[gvr.RowIndex].Cells[2]).Text.ToString().Trim();        //以字符流的形式下载文件 
        FileStream fs = new FileStream(filePath, FileMode.Open);
        byte[] bytes = new byte[(int)fs.Length];
        fs.Read(bytes, 0, bytes.Length);
        fs.Close();
        Response.ContentType = "application/octet-stream";        //通知浏览器下载文件而不是打开 
        Response.AddHeader("Content-Disposition", "attachment;  filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
        Response.BinaryWrite(bytes);
        Response.Flush();
        Response.End();上面代码是下载文件的代码。数据库中存储的是文件路径。
怎样实现直接将文件打开。不是在浏览其中显示,而是直接将此文件打开,比如将TXT文件直接打开那种

解决方案 »

  1.   

    将里面的内容读取出来,然后再生成静态页面,再跳转到这个静态页面的URL即可(或者直接把内容输出到当前页面也行)
      

  2.   

    这样可以。但是内容是显示在WEB里的。我想让他显示在记事本或word里
      

  3.   

    Response.AppendHeader("Content-Disposition",   "inline;filename="   +     HttpUtility.UrlEncode("文件名称"));   
    不是下载,是显示试试看
      

  4.   

    谢谢,你这样可以在Web里显示内容。但是我想将这个文件打开,比如说我下载的word类型的文件,那么点击后内容是在word里显示的,请问这样怎么实现。