将FileStream写入本地路径而不是服务器

时间:2014-10-06 14:37:21

标签: vb.net filestream

我有以下代码成功运作:

Protected Sub ExportExcel_Click(sender As Object, e As EventArgs) Handles ExportExcel.Click
        Dim warnings As Warning()
        Dim streamids As String()
        Dim mimeType As String
        Dim encoding As String
        Dim filenameExtension As String
        Dim fileName As String = "D:\Report" & DateTime.Now.ToString("yyyyMMdd_HHmmss") & ".xls"
        Dim bytes As Byte() = ReportViewer1.LocalReport.Render("Excel", Nothing, mimeType, encoding, filenameExtension, streamids, warnings)

        Using fs As New FileStream(fileName, FileMode.Create)
            fs.Write(bytes, 0, bytes.Length)
        End Using
        lblMessage.Text = Functions.GetMessageConfirm("Report downloaded successfully in your D:/ at: " & Now.ToString)
    End Sub

此代码将文件保存在Web服务器中。我想将文件保存在客户端计算机上。

1 个答案:

答案 0 :(得分:0)

你可能已经到了一半了。无论如何,您不仅可以在客户端上保存文件。客户端是webbrowsers,他们运行JavaScript。

您可以使用webbrowsers的下载功能,让他们下载您刚刚创建的文件。为此,请将服务器上的输出放在可以下载的目录中,然后将新URL返回给客户端。