by gareth
7. November 2007 19:29
I was trying to export some data the other day and ran into a few issues with the Crystal Reports Viewer for ASP .NET, When using the built-in Export function
the entire Crystal Report was exported when in actual fact all I needed was the current view eg a single group is selected from the group tree.
The snippet below will allow you do this, it will also send the output back to the browser. The Important part being line 7 which gets the current
view from our crystal viewer control. I have been unable to find much information regarding this, so this was very hit and miss for me.
Dim rs As NonHTTPCachedReportSource = CType(crvReportViewer.ReportSource,NonHTTPCachedReportSource)
Dim exp As ExportOptions = New ExportOptions()
exp.ExportFormatType = ExportFormatType.TabSeperatedText
exp.FormatOptions = New PdfRtfWordFormatOptions()
Dim req As ExportRequestContext = New ExportRequestContext()
req.ExportInfo = exp
req.ViewContext = crvReportViewer.ViewInfo.ViewContext
Dim exported As System.IO.MemoryStream = CType(rs.ExportToStream(req), _
System.IO.MemoryStream)
Response.Charset = "UTF-8"
Response.ContentEncoding = System.Text.Encoding.GetEncoding(1252)
Response.AddHeader("content-disposition", "Attachment;filename=ExportedData.tsv")
Response.AddHeader("Cache-Control", "no-store")
Response.AddHeader("Pragma", "no-cache")
Response.Expires = -1
Response.Clear()
Dim b(exported.Length) As Byte
exported.Read(b, 0, CType(exported.Length, Integer))
Response.BinaryWrite(b)
Response.Flush()
Response.End()
My Original post on the diamond forums can be found here, A similar post which appeared after mine can be found here.Hope this helps someone.Cheers