在asp.net

时间:2016-09-09 17:43:25

标签: asp.net

我正在尝试在ASP.net中打开word文档。该文档存在于ASP.net应用程序内的文件夹c:\ AppName \ Word Docs \ Requirements Docs.docx下  这是我试图打开它的方式:

<asp:LinkButton ID="lnkReqDoc" runat="server"  Text="App Requirements"  ></asp:LinkButton>

后面的代码是这样的:

Protected Sub lnkReqDoc_Click(sender As Object, e As System.EventArgs) Handles lnkReqDoc.Click

        Dim fs1 As FileStream = New FileStream("~/word Docs/", FileMode.Open, FileAccess.Read)
        Dim data1() As Byte = New Byte(fs1.Length) {}
        fs1.Read(data1, 0, data1.Length)
        fs1.Dispose()
        Response.AddHeader("content-disposition", "attachment;filename=" + "Requirements Docs.docx")
        Response.BinaryWrite(data1)
        Response.End()
        fs1.Close()
    End Sub

当我尝试在本地打开文档时,我收到一条错误消息:

Could not find a part of the path 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\~\word Docs\'.

在我的本地,如果我只是做下面的行然后它工作正常,它打开word文档,但当我在服务器上部署下面的代码然后它说“文件或目录未找到”

<asp:LinkButton ID="lnkReqDoc" runat="server"  Text="App Requirements" PostBackUrl="~/word Docs/Requirements.docx" ></asp:LinkButton>

我应该怎么做才能在服务器和本地打开文件。

任何帮助将不胜感激。

0 个答案:

没有答案