我想在DataGrid中绑定下载文件的路径,点击就下载这个文件,请问代码怎么写?

解决方案 »

  1.   

    <a href='<%#DataBinder.Eval(Container.DataItem,"url")%>'>下载</a>
      

  2.   

    由于我放的是Word文档,但这样做只能在网页中打开这个文档,无法实现下载!
      

  3.   

    由于我放的是Word文档,但这样做只能在网页中打开这个文档,无法实现下载!
    ========================
    这个是客户端文件关取的问题.根程序没关系. 或者在<a 中加个 target='_new'试试
      

  4.   

    哦,谢谢!
    我以前写代码是Response.Redirect(路径)就可以实现下载,但现在不行了,不知为什么?
      

  5.   

    我以前写代码是Response.Redirect(路径)就可以实现下载,但现在不行了,不知为什么?
    ============
    这根代码没关系.是客户机文件关联的问题.
      

  6.   

    我发现用<a href="文件路径">下载</a>这种方法对.exe,.rar等文件可用,对于.doc,.mht等文件可时没用,现在我遇到的就是没用的情况!
      

  7.   

    我用<a href="文件路径">下载</a>这种方法是可以行得通的呀,包括doc文档
      

  8.   

    public string down(string url)
    {
    System.IO.FileInfo DownloadFile = new FileInfo(url); 
    try
    {

    Response.Clear();
    Response.ContentType = "application/octet-stream";
    Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));

    Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
    Response.WriteFile(DownloadFile.FullName);
    Response.Flush();
    Response.End();

    }

    catch(System.IO.FileNotFoundException)
    {
    sx.common.massage.Show(this,"此文件已不存在");
    sx.common.massage.ResponseScript(this,"window.close()");
    } return DownloadFile.FullName;
    }单建一个download的页面 然后把地址导向到这个页面就可以了