Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Export crystal report to word document? Post Reply Post New Topic
Author Message
Puneri
Newbie
Newbie


Joined: 19 Jun 2008
Location: Kuwait
Online Status: Offline
Posts: 10
Quote Puneri Replybullet Topic: Export crystal report to word document?
    Posted: 09 Jul 2008 at 12:25am
Hello

I want to save crystal report output as word document on server.
I've written following code. But I'm getting error at highlighted line.
CrEmReport is my crystalreportviewer object.

Me.CrEmReport.ParameterFieldInfo.Clear()
Me.CrEmReport.ReportSource =Server.MapPath("EmCallupReport.rpt")
Dim ParamFields As ParameterFields = Me.CrEmReport.ParameterFieldInfo
Dim emTicketId As New ParameterField
emTicketId.Name = "VTICKETID"
Dim emTicketId_Value As New ParameterDiscreteValue
emTicketId_Value.Value = objTicket.ticketId
emTicketId.CurrentValues.Add(emTicketId_Value)
ParamFields.Add(emTicketId)


For Each cnInfo As TableLogOnInfo In Me.CrEmReport.LogOnInfo

cnInfo.ConnectionInfo = ConnInfo
Next
Dim objReportDoc As New ReportDocument
objReportDoc = CrEmReport.ReportSource
    objReportDoc.ExportToDisk(ExportFormatType.PortableDocFormat, "\\app_data\\uploads\\Reports\\Emergency\\Emergency_" & objTicket.ticketId)


I'm getting error at red line as,
Unable to cast object of type 'CrystalDecisions.ReportSource.NonHTTPCachedReportSource' to type 'CrystalDecisions.CrystalReports.Engine.ReportDocument'

From error I can understand that i'm assigning reportdocument object some other type of object. But to use export method I need reportdocument object pointing to my report. How to achieve this???
Need help urgently.....  Cry
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 14 Jul 2008 at 1:29pm
What type of object is CrEmReport?  Is it a CrystalReportsViewer control?
 
If all you're trying to do is export the report without showing it, then you would be better off loading the report directly into a ReportDocument object using the .Load method.  You then set the parameters and the logins using the methods and properties of the ReportDocument.  At that point, you can call ExportToDisk on the ReportDocument that you already have.
 
-Dell
IP IP Logged
Puneri
Newbie
Newbie


Joined: 19 Jun 2008
Location: Kuwait
Online Status: Offline
Posts: 10
Quote Puneri Replybullet Posted: 14 Jul 2008 at 11:47pm
CrEmReport is my crystalreportviewer object.

I want to display report to user. But User should not be able to export to local machine. Instead I want to save report to disk.
IP IP Logged
Puneri
Newbie
Newbie


Joined: 19 Jun 2008
Location: Kuwait
Online Status: Offline
Posts: 10
Quote Puneri Replybullet Posted: 15 Jul 2008 at 2:45am
Dim objReportDoc As New ReportDocument
objReportDoc.Load("EmCallupReport.rpt",OpenReportMethod.OpenReportByDefault)


At runtime i'm getting error as Load report failed. System could find specified file.


This aspx page and .rpt files lie in same folder. How to load .rpt?
                   
IP IP Logged
Puneri
Newbie
Newbie


Joined: 19 Jun 2008
Location: Kuwait
Online Status: Offline
Posts: 10
Quote Puneri Replybullet Posted: 21 Jul 2008 at 6:50am
Hi
I've modified above code as follows.
Dim objReportDoc As New ReportDocument
                objReportDoc.Load(Server.MapPath("EmCallupReport.rpt"), OpenReportMethod.OpenReportByDefault)
                objReportDoc.SetParameterValue("VTICKETID", objEmTicket.ticketId)
                objReportDoc.SetDatabaseLogon("HDLOCAL", "HDLOCAL", "HDLOCAL", "")
                objReportDoc.ExportToDisk(ExportFormatType.WordForWindows, Server.MapPath("\\app_data\\uploads\\Reports\\Emergency"))

I'm getting error at last line as,

Source        : System.Web
Method        : MapPathActual
Error        : Failed to map the path '/app_data/uploads/Reports/Emergency'.
Stack Trace    : at System.Web.Hosting.HostingEnvironment.MapPathActual(VirtualPath virtualPath, Boolean permitNull)
   at System.Web.VirtualPath.MapPathInternal()
   at System.Web.HttpRequest.MapPath(VirtualPath virtualPath, VirtualPath baseVirtualDir, Boolean allowCrossAppMapping)
   at System.Web.HttpServerUtility.MapPath(String path)
   at frmEmergency.btnSubmit_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\Helpdesk_2007_02\frmCreateEmTicket.aspx.vb:line 183
How to specify location?

IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 21 Jul 2008 at 7:26am
As I said in response to your PM (I'm going to repost here in case anyone else needs the answer), this is probably an access rights issue. 
 
ASP.NET application usually run under a user ID that is local to the machine where they're running.  This user ID does NOT have access to your network and can't be given that access.  So, in order to access network resources you need to have a network User ID for your ASP.NET applications to run under.  There is a way of configuring IIS to use this new ID for your applications, but I'm not exactly sure how to set that up because our Network folks handle that configuration.
 
-Dell
IP IP Logged
Ishfaq
Newbie
Newbie


Joined: 21 Jul 2008
Location: Saudi Arabia
Online Status: Offline
Posts: 1
Quote Ishfaq Replybullet Posted: 21 Jul 2008 at 11:53pm

Hi puneri... use below code.once you get the report displayed,then you can use the tool bar of the Report viewer to export to any other format.

 
 

 

    Dim crtableLogoninfos As New TableLogOnInfos

    Dim crtableLogoninfo As New TableLogOnInfo

    Dim crConnectionInfo As New ConnectionInfo

    ''   Dim crdatabase As Database

    Dim CrTables As Tables

    Dim CrTable As Table

    Dim crReportDocument As New ReportDocument

 

   

        crReportDocument.Load("Put report path here")

        crConnectionInfo.ServerName = "Server Name here"

        crConnectionInfo.DatabaseName = "Database Name Here"

        crConnectionInfo.UserID = "user id"

        crConnectionInfo.Password = "password"

 

        CrTables = crReportDocument.Database.Tables

 

        'Set the connection info to each table present in the report

        For Each CrTable In CrTables

            crtableLogoninfo = CrTable.LogOnInfo

            crtableLogoninfo.ConnectionInfo = crConnectionInfo

            CrTable.ApplyLogOnInfo(crtableLogoninfo)

        Next

 

'Sub Report Log on*****************************'

        Dim li_Sectionindex As Integer

        Dim li_ObjCtr As Integer

        Dim li_TableCtr As Integer

        Dim l_SubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject

        Dim l_SubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument

 

        For li_Sectionindex = 0 To crReportDocument.ReportDefinition.Sections.Count - 1

            For li_ObjCtr = 0 To crReportDocument.ReportDefinition.Sections(li_Sectionindex).ReportObjects.Count - 1

                With crReportDocument.ReportDefinition.Sections(li_Sectionindex)

                    If .ReportObjects(li_ObjCtr).Kind = CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then

                        l_SubReportObject = CType(.ReportObjects(li_ObjCtr), CrystalDecisions.CrystalReports.Engine.SubreportObject)

                        l_SubRepDoc = l_SubReportObject.OpenSubreport(l_SubReportObject.SubreportName)

 

                        For li_TableCtr = 0 To l_SubRepDoc.Database.Tables.Count - 1

                            l_SubRepDoc.Database.Tables(li_TableCtr).ApplyLogOnInfo(crtableLogoninfo)

                        Next

 

 

                    End If

                End With

            Next

        Next

 

        '****************End Sub Report log on********************************'

 

 

 

 

 

        crviewer.ReportSource = crReportDocument

 
 
 
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.017 seconds.