none
Export to Word in 2005 RRS feed

  • General discussion

  • Hi All,

    We can export Report Viewer output in MS Word in the following way.Just place a button on ASPX page and on the click event of the button, write the following code......................

    Private Sub lnkExpotToWord_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkExpotToWord.Click
            Dim buffer As Byte(), f As String, fs As System.IO.FileStream
            f = System.IO.Path.GetTempFileName()
            System.IO.Path.ChangeExtension(f, "doc")
            buffer = ReportViewer1.ServerReport.Render("HTML3.2", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)

            fs = New System.IO.FileStream(f, System.IO.FileMode.Create)
            fs.Write(buffer, 0, buffer.Length)
            fs.Close()
            fs.Dispose()


            Response.ContentType = "Application/doc"
            Response.WriteFile(f)
            Response.AddHeader("content-disposition", "attachment; filename=FileName.doc")

            Response.End()
            System.IO.File.Delete(f)

        End Sub



    Aftab Ansari
    Thursday, July 17, 2008 9:39 AM

All replies