【问题标题】:how to open an word document on click of link button如何在单击链接按钮时打开word文档
【发布时间】:2010-01-18 09:19:59
【问题描述】:

一旦用户单击该链接按钮,我的 gridview 中有一个链接按钮,我需要打开一个 word 文档(文档存储在服务器中的路径如下 c:/abc/doc/abc1.doc)所以现在我应该允许用户下载该文档以查看它。

如何实现 谢谢

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    您应该考虑使用 TransmitFile 方法而不是 WriteFile 方法。对于您正在做的事情,更多的是efficient

    protected void btnPurchaseOrderOpen_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=one.pdf");
        Response.TransmitFile(@"c:\test\one.pdf");
        Response.End();
    }
    

    【讨论】:

      【解决方案2】:

      asp.net,表示你想用浏览器打开文档。

      这里是简单的sn-p

          string fPath = @"c:/abc/doc/abc1.doc";
          FileInfo myDoc = new FileInfo(fPath);
      
          Response.Clear();
          Response.ContentType = "Application/msword";
          Response.AddHeader("content-disposition", "attachment;filename=" + myDoc.Name);
          Response.AddHeader("Content-Length", myDoc.Length.ToString());
          Response.ContentType = "application/octet-stream";
      
          Response.WriteFile(myDoc.FullName);
      
          Response.End();
      

      【讨论】:

        【解决方案3】:

        喂,

        在您的项目中添加对 word 对象库的引用。 那就试试这个

         Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
            app.Visible = true;
            object visible = true;
            object fileName = @"C:\temp\sample.doc";
            object optional = System.Type.Missing;
            Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(ref fileName, ref optional, ref 
                optional, ref optional, ref optional, ref optional, ref optional, ref 
                optional, ref optional, ref optional,ref optional,ref optional,ref optional,ref optional,ref optional,ref optional);
        

        如果您想要网络浏览器的东西,只需看看 saar 的答案

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-03-12
          • 2014-07-11
          • 1970-01-01
          • 2017-07-16
          • 1970-01-01
          • 2018-07-10
          • 2022-07-30
          相关资源
          最近更新 更多