例如已知C:\test.doc
现在一个test.aspx上有个按钮如何实现点击中就
运行系统自带的word程序,并打开这个word文件。

解决方案 »

  1.   

    string tmpFileName = "c:\\test.doc";
    FileInfo tmpFI = new FileInfo(tmpFileName);
    Response.Clear();
    Response.ClearHeaders();
    Response.Buffer = false;

    Response.AppendHeader("Content-Disposition","attachment;filename=" +HttpUtility.UrlEncode(Path.GetFileName(tmpFileName),System.Text.Encoding.UTF8 ));
    Response.AppendHeader("Content-Length",tmpFI.Length.ToString());
    Response.ContentType="application/octet-stream";
    Response.WriteFile(tmpFileName);
    Response.Flush();
    Response.End();//这个不光能打开word,其他文件也行,不过缺点是一次打开,如果要打开大文件(比如100MB的DOC),需要再改进一下,不然如果多人同时打开服务器承受不了的。
      

  2.   

    检查一下你的代码,是不是因为没有判断IsPostBack导致以上代码执行了两次。
      

  3.   

    最好把DOC和EXECLE文件放在虚拟目录中,然后使用<a href="virtualpath/dd.doc"></a>IE会自动使用相关的程序打开.