Dim db1 As New DBLevel Dim conn = db1.GetCon() Dim cmd As New SqlCommand Dim da As New SqlDataAdapter Dim dss As New DataSet cmd.CommandText = "[procReport" cmd.Parameters.Add(New SqlParameter("@ID", SqlDbType.NVarChar)).Value = Request.QueryString("ID") cmd.CommandType = CommandType.StoredProcedure cmd.Connection = conn da.SelectCommand = cmd da.Fill(dss) oRPT.Load(Server.MapPath("rptReports/ReportWord.rpt")) oRPT.SetDataSource(dss.Tables(0)) oRPT.SetParameterValue("@ID", Request.QueryString("ID")) Me.CrystalReportViewer1.ReportSource = oRPT Me.CrystalReportViewer1.DataBind() Dim margins = New PageMargins oRPT.PrintOptions.PaperSize = PaperSize.PaperA4 margins = oRPT.PrintOptions.PageMargins margins.leftMargin = 750 margins.topMargin = 350 margins.bottomMargin = 40 margins.rightMargin = 550 Try Dim CrExportOptions As CrystalDecisions.Shared.ExportOptions Dim CrDiskFileDestinationOptions As New CrystalDecisions.Shared.DiskFileDestinationOptions() Dim CrFormatTypeOptions As New CrystalDecisions.Shared.PdfRtfWordFormatOptions() CrDiskFileDestinationOptions.DiskFileName = Server.MapPath("~/Report.doc") Dim targetFile As System.IO.FileInfo = New System.IO.FileInfo(Server.MapPath("~/Report.doc")) CrExportOptions = oRPT.ExportOptions With CrExportOptions .ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile .ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows .DestinationOptions = CrDiskFileDestinationOptions .FormatOptions = CrFormatTypeOptions End With oRPT.Export() Response.Clear() Response.AddHeader("Content-Disposition", "attachment; filename=" + targetFile.Name) Response.AddHeader("Content-Length", targetFile.Length.ToString) Response.ContentType = "application/octet-stream" Response.WriteFile(targetFile.FullName) Catch ex As Exception Response.Write(ex.ToString) End Try oRPT.Clone() oRPT.Dispose()
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)