locked
Export error in asp.net Badly need Help!! RRS feed

  • Question

  • User-1235508292 posted
    Hello.. I can display the report ok but when I export to pdf etc i was getting the login failed error.. after speaking with crystal reports they said I should build my report etc in page init and also again on the export button on click event. NOW I am getting the following error. Exception has been thrown by the target of an invocation. Now!!: am I closer to a solution or am I further away?????? can anybody help as this is driving me mad. below is a copy of the code Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared Imports System.Data.SqlClient Imports System.IO Public Class PPCReport Inherits System.Web.UI.Page Protected WithEvents exportTypesList As System.Web.UI.WebControls.DropDownList Protected WithEvents exportByType As System.Web.UI.WebControls.Button Private exportPath As String Private myDiskFileDestinationOptions As DiskFileDestinationOptions Protected WithEvents myCrystalReportViewer As CrystalDecisions.Web.CrystalReportViewer Protected WithEvents cR_PPCReport1 As webDevVB.CR_PPCReport Protected WithEvents Menu1 As skmMenu.Menu Protected WithEvents lblMessage As System.Web.UI.WebControls.Label Protected WithEvents crppC11 As webDevVB.CRPPC1 Protected WithEvents FirstPage_button As System.Web.UI.WebControls.Button Protected WithEvents Back_button As System.Web.UI.WebControls.Button Protected WithEvents forward_button As System.Web.UI.WebControls.Button Protected WithEvents last_button As System.Web.UI.WebControls.Button Protected WithEvents cR_CustomerSP1 As webDevVB.CR_CustomerSP Protected WithEvents btnRefresh As System.Web.UI.WebControls.Button Protected WithEvents lstZoom As System.Web.UI.WebControls.DropDownList Protected WithEvents btnSearch As System.Web.UI.WebControls.Button Protected WithEvents txtSearch As System.Web.UI.WebControls.TextBox Private myExportOptions As ExportOptions #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.cR_PPCReport1 = New webDevVB.CR_PPCReport Me.crppC11 = New webDevVB.CRPPC1 Me.cR_CustomerSP1 = New webDevVB.CR_CustomerSP ' 'cR_PPCReport1 ' Me.cR_PPCReport1.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation Me.cR_PPCReport1.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize Me.cR_PPCReport1.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Upper Me.cR_PPCReport1.PrintOptions.PrinterDuplex = CrystalDecisions.Shared.PrinterDuplex.Default ' 'crppC11 ' Me.crppC11.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation Me.crppC11.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize Me.crppC11.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Upper Me.crppC11.PrintOptions.PrinterDuplex = CrystalDecisions.Shared.PrinterDuplex.Default ' 'cR_CustomerSP1 ' Me.cR_CustomerSP1.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation Me.cR_CustomerSP1.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize Me.cR_CustomerSP1.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Upper Me.cR_CustomerSP1.PrintOptions.PrinterDuplex = CrystalDecisions.Shared.PrinterDuplex.Default End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() 'ConfigureCrystalReports() Dim myReport = New CR_CustomerSP Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo myConnectionInfo.ServerName = "MYSERVER" myConnectionInfo.DatabaseName = "MYDB" myConnectionInfo.UserID = "MYUSER" myConnectionInfo.Password = "MYPASS" SetDBLogonForReport(myConnectionInfo, myReport) If Not IsPostBack Then exportTypesList.DataSource = System.Enum.GetValues(GetType(CeExportType)) exportTypesList.DataBind() End If myCrystalReportViewer.ReportSource = myReport End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Not IsPostBack Then Dim userName, AccessLevel userName = Session("UserName") AccessLevel = Session("AccessLevel") 'lblUserlevel.Text = AccessLevel If AccessLevel = 9 Then Menu1.UserRoles.Add("admin") Else Menu1.UserRoles.Add("eng") End If Menu1.DataSource = Server.MapPath("RoleXML.xml") Menu1.DataBind() End If End Sub Private Sub exportByType_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exportByType.Click ExportSetup() ExportSelection() ExportCompletion() End Sub Public Sub ExportSetup() exportPath = "C:\Exported" If Not System.IO.Directory.Exists(exportPath) Then System.IO.Directory.CreateDirectory(exportPath) End If myDiskFileDestinationOptions = New DiskFileDestinationOptions myExportOptions = cR_CustomerSP1.ExportOptions() myExportOptions.ExportDestinationType = ExportDestinationType.DiskFile End Sub Public Sub ExportSelection() Select Case exportTypesList.SelectedIndex Case CeExportType.DOC_MicrosoftWord ConfigureExportToDoc() Case CeExportType.PDF_PortableDocument ConfigureExportToPdf() 'Case CeExportType.RPT_CrystalReport 'ConfigureExportToRpt() Case CeExportType.RTF_RichTextFormat ConfigureExportToRtf() Case CeExportType.XLS_MicrosoftExcel ConfigureExportToXls() 'Case CeExportType.HTML_Html32 'ConfigureExportToHtml32() 'Case CeExportType.HTML_Html40 'ConfigureExportToHtml40() End Select End Sub Public Sub ExportCompletion() Try Dim myReport = New CR_CustomerSP Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo myConnectionInfo.ServerName = "WWW001GB" myConnectionInfo.DatabaseName = "PPC_DriverAudit" myConnectionInfo.UserID = "PIRWEB" myConnectionInfo.Password = "CWMBACH" SetDBLogonForReport(myConnectionInfo, myReport) myCrystalReportViewer.ReportSource = myReport myReport.Export() lblMessage.Text = MessageConstants.SUCCESS Catch ex As Exception lblMessage.Text = MessageConstants.FAILURE & ex.Message End Try lblMessage.Visible = True End Sub Public Sub ConfigureExportToDoc() myExportOptions.ExportFormatType = ExportFormatType.WordForWindows myDiskFileDestinationOptions.DiskFileName = exportPath & "Word.doc" myExportOptions.DestinationOptions = myDiskFileDestinationOptions End Sub Public Sub ConfigureExportToPdf() myExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat myDiskFileDestinationOptions.DiskFileName = exportPath & "PortableDoc.pdf" myExportOptions.DestinationOptions = myDiskFileDestinationOptions End Sub Public Sub ConfigureExportToRpt() myExportOptions.ExportFormatType = ExportFormatType.CrystalReport myDiskFileDestinationOptions.DiskFileName = exportPath & "Report.rpt" myExportOptions.DestinationOptions = myDiskFileDestinationOptions End Sub Public Sub ConfigureExportToRtf() myExportOptions.ExportFormatType = ExportFormatType.RichText myDiskFileDestinationOptions.DiskFileName = exportPath & "RichTextFormat.rtf" myExportOptions.DestinationOptions = myDiskFileDestinationOptions End Sub Public Sub ConfigureExportToXls() myExportOptions.ExportFormatType = ExportFormatType.Excel myDiskFileDestinationOptions.DiskFileName = exportPath & "Excel.xls" myExportOptions.DestinationOptions = myDiskFileDestinationOptions End Sub Public Sub ConfigureExportToHtml32() myExportOptions.ExportFormatType = ExportFormatType.HTML32 Dim html32FormatOptions As HTMLFormatOptions = New HTMLFormatOptions html32FormatOptions.HTMLBaseFolderName = exportPath & "Html32Folder" html32FormatOptions.HTMLFileName = "html32.html" html32FormatOptions.HTMLEnableSeparatedPages = False html32FormatOptions.HTMLHasPageNavigator = False myExportOptions.FormatOptions = html32FormatOptions End Sub Public Sub ConfigureExportToHtml40() myExportOptions.ExportFormatType = ExportFormatType.HTML40 Dim html40FormatOptions As HTMLFormatOptions = New HTMLFormatOptions html40FormatOptions.HTMLBaseFolderName = exportPath & "Html40Folder" html40FormatOptions.HTMLFileName = "html40.html" html40FormatOptions.HTMLEnableSeparatedPages = True html40FormatOptions.HTMLHasPageNavigator = True html40FormatOptions.FirstPageNumber = 1 html40FormatOptions.LastPageNumber = 3 myExportOptions.FormatOptions = html40FormatOptions End Sub Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo, ByVal myReportDocument As ReportDocument) Dim myTables As Tables = myReportDocument.Database.Tables Dim myTable As CrystalDecisions.CrystalReports.Engine.Table For Each myTable In myTables Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo myTableLogonInfo.ConnectionInfo = myConnectionInfo myTable.ApplyLogOnInfo(myTableLogonInfo) Next End Sub End Class
    Tuesday, May 25, 2004 12:12 PM

All replies

  • User600176218 posted
    There's all sorts of stuff going on in here that doesn't need to be. Take all that code out of your InitializeComponent(), and put it in to the page_init. Page_init fires before page_load, so if your report requires any of that security information, you will need to put it into the page_init. Where are these export buttons? Are they on the same page as the CrystalReportViewer control? If so, you may need to rebuild your report to export it when you click the button. Also, look at this line in your code: >exportPath = "C:\Exported" and see if this helps: http://dotnetjunkies.com/WebLog/richard.dudley/archive/2004/05/24/14362.aspx
    Tuesday, May 25, 2004 1:18 PM
  • User-1235508292 posted
    Thanks, i trimmed down the code a bit and placed all in page init and I can now export to a directory on my web server as your hint re exportpath suggested.. But I want the user to save the file down to their own computer. Is there a way to do this and better still can I allow them to save it where they want similar to the dialog boxes when downloading files etc
    Wednesday, May 26, 2004 5:10 AM
  • User600176218 posted
    Easy. Sorry to send you back to the blog--this way I can keep all these code bits handy for the next guy who asks the same question. In each example, the browser's download handler will be automatically triggered. http://dotnetjunkies.com/WebLog/richard.dudley/archive/2004/05/26/14543.aspx
    Wednesday, May 26, 2004 8:47 AM
  • User-1235508292 posted
    Many thanks.. i like the second option best..you are a life saver.. especially as business objects did not really offer me any solutions.
    Wednesday, May 26, 2004 9:18 AM
  • User-1235508292 posted
    just one more thing.. in my reports there are options to print or export to excel. I notice however that when any of the export buttons is clicked the original report is lost.. is there a way to export to a new window and leave the orginal intact for further user use
    Wednesday, May 26, 2004 9:29 AM
  • User600176218 posted
    You should just pull up a chair and see what else is in my project! From reading your code above, it looks like the page loads and displays your report. If that's the case, I'd add a small if...then statement to the display page (some_report.aspx in the snippet below). Something like this: if request.querystring("export")=true then ' export report else ' display report and option buttons end if I would change the OnClick of the export button to be just this: Dim strPop As String = "<script language='javascript'>" _ & "window.open('some_report.aspx?export=true','Report')</script>" Page.RegisterStartupScript("Pop", strPop) This will cause a pop-up window to open, containing the page that displayes your report. The second export optionI showed you will clear the response stream, and dump out the report to the browser.
    Wednesday, May 26, 2004 11:37 AM
  • User-1235508292 posted
    Perfect, or so I thought!!! everything working hunkydory on my dev m/c.. but when i deploy the web app to our Dev web server (server 2000 with .net framwork installed) the reports just hang and will not open??? any ideas
    Thursday, May 27, 2004 3:39 AM
  • User600176218 posted
    Which report hangs--the first one with the export buttons, or the pop-up window?
    Thursday, May 27, 2004 10:09 AM
  • User-1235508292 posted
    the export ones..
    Thursday, May 27, 2004 10:17 AM
  • User600176218 posted
    Does the pop-up open OK? Are you running URLScan on the remote server? If so, you'll need to add PDF to the allowable extensions. The log will have an error entry confirming this. If no URLScan, ignore this.
    Thursday, May 27, 2004 1:29 PM
  • User-1235508292 posted
    I did not use the pop up on this occasion as I already had the reports opening in a new window from a skmmenu. I added a web setup project in the same soloution as my web app as per businessobjects PDF, but I was unsure of the process after the final build..they did not tell you how to activate it???? do I have to copy the websetup project folder (which was not in the same inetpub folder as the webapp) and add to the remote server web site folder then run setup in the debug folder.. if so I did this! but no difference As far as I know we do not have urlscan.. but the reports hang on initial opening before the export buttons are clicked I have little experience in .net so perhaps I did something wrong in the deployment.. any guidance would be appreciated
    Friday, May 28, 2004 4:05 AM
  • User663331046 posted

    Hmmm, nice user name and password you got in there dude!

    Thursday, September 2, 2010 8:10 AM