pdf export with reportID instead of path and filename

I know how to open a report via ASP when using the full path and filename with ReportClientDocument.Open..
Then export to a PDF that displays in the browser with PrintOutputController.Export..

But how can I open the report using the 'reportid'..
I am attempting to alter the following code to export to pdf...


------------------------------------------------------
<%@ Language=VBScript codepage=65001%>

<% Option Explicit
Response.ExpiresAbsolute = Now() - 1
const CLOSED_RPT_ID = "closedreportid"
const RPT_ID = "reportid"
const RPT_SOURCE = "reportsource"

Dim requestMethod
requestMethod = UCase(Request.ServerVariables("REQUEST_METHOD"))

Dim serializedRptSrc, reportid, closedreportid
if (requestMethod = "POST") then
    serializedRptSrc = Request.Form(RPT_SOURCE)
    closedreportid = Request.Form(CLOSED_RPT_ID)
else
    serializedRptSrc = Request.QueryString(RPT_SOURCE)
    closedreportid = Request.QueryString(CLOSED_RPT_ID)
end if

' reportid is always passed in the URL
reportid = Request.QueryString(RPT_ID)

if (Not (IsEmpty(closedreportid) OR (Len(closedreportid) = 0))) then
    ' Clear the report source in session with the given closedreportid
    Session.Contents.Remove(closedreportid)
end if

if (Not (IsEmpty(reportid) OR (Len(reportid) = 0))) then
    On Error Resume Next
   
    Dim objectFactory
    ' Use the version dependent prog id for side by side support
    ' (i.e. to maintain consistency when multiple versions of the product is installed)
    Set objectFactory = CreateObject("CrystalReports11.ObjectFactory.1")
   
    Dim HTMLViewer

    Set HTMLViewer = ObjectFactory.CreateObject("CrystalReports.CrystalReportViewer")
    With HTMLViewer
        .Name = "htmlpreview"
        .IsOwnForm = true
        .IsOwnPage = true
        .HasRefreshButton = false
        .HasExportButton = false
        .HasPrintButton = false
    End With
       
    if (Not (IsEmpty(serializedRptSrc) OR (Len(serializedRptSrc) = 0))) then
        ' Got a seralizedRprtSrc string
        ' need to deserialize the report source string and pass to viewer
        Dim XMLSerializer
        Set XMLSerializer = ObjectFactory.CreateObject("CrystalReports.SAXXMLSerializer")
       
        XMLSerializer.SetObjectCreator ObjectFactory    
        HTMLViewer.ReportSource = XMLSerializer.CreateObjectFromString(serializedRptSrc)
       
        set Session.Contents(reportid) = HTMLViewer.ReportSource
    else
      ' Try to load report source from session
        HTMLViewer.ReportSource = Session.Contents(reportid)
    end if

    HTMLViewer.URI = Request.ServerVariables("Path_Info") + "?" + RPT_ID + "=" + reportid
   
    call HTMLViewer.ProcessHttpRequest(Request, Response, Session)
    if Err.number <> 0 then
        Response.Write Err.Description
        Err.Clear
    end if          

end if

%>
------------------------------
LVL 1
Stella PauleyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mlmccCommented:
What is the report id?

Are you trying to export a report while it is being viewed?

There is an export sample in this ASP code
http://support.businessobjects.com/communityCS/FilesAndUpdates/aspxmps10.exe.asp

mlmcc
0
Stella PauleyAuthor Commented:
in a way..
Im working with the new Crystal Reports XI Developer and Server..
The developer has a button 'HTML Preview' that launches the asp code that I included above with the following url..

http://server/crystalreportviewers11/preview.asp?reportid={01C07995-D6E2-4F90-A445-16A5B54136E4}

0
mlmccCommented:
No idea. That is a new feature for CR XI that I hadn't heard or read about.

mlmcc
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Stella PauleyAuthor Commented:
Im getting close.. I got it to work once...
but when I closed it and re-ran it.. It started coming up with a blank window.. no error.. no report...

I'll keep working on it and will update once I get it working better...
0
Stella PauleyAuthor Commented:
Well.. I've got it working.. however.. when you hit the HTMLPreview button.. you get a blank window.. then if you hit the refresh button the PDF will load.. I don't know why it works this way and I can't figure out a way to auto refresh it..
I tried response.redirect but it still works the same way..

Here is what I have:
------------------------------------------------------------------------
<%@ Language=VBScript codepage=65001%>

<% Option Explicit
   On Error Resume Next
Response.ContentType="application/pdf"
Response.ExpiresAbsolute = Now() - 1
const CLOSED_RPT_ID = "closedreportid"
const RPT_ID = "reportid"
const RPT_SOURCE = "reportsource"

Dim requestMethod
requestMethod = UCase(Request.ServerVariables("REQUEST_METHOD"))

Dim serializedRptSrc, reportid, closedreportid
if (requestMethod = "POST") then
    serializedRptSrc = Request.Form(RPT_SOURCE)
    closedreportid = Request.Form(CLOSED_RPT_ID)
else
    serializedRptSrc = Request.QueryString(RPT_SOURCE)
    closedreportid = Request.QueryString(CLOSED_RPT_ID)
end if

' reportid is always passed in the URL
reportid = Request.QueryString(RPT_ID)

if (Not (IsEmpty(closedreportid) OR (Len(closedreportid) = 0))) then
    ' Clear the report source in session with the given closedreportid
    Session.Contents.Remove(closedreportid)
end if


if (Not (IsEmpty(reportid) OR (Len(reportid) = 0))) then



   
    Dim objectFactory
    ' Use the version dependent prog id for side by side support
    ' (i.e. to maintain consistency when multiple versions of the product is installed)
    Set objectFactory = CreateObject("CrystalReports11.ObjectFactory.1")

Dim expOpt, formatOpt
Set expOpt = ObjectFactory.CreateObject("CrystalReports.ExportOptions")
Set formatOpt = ObjectFactory.CreateObject("CrystalReports.PDFExportFormatOptions")

Dim crReportExportFormatPDF
crReportExportFormatPDF = 5

expOpt.FormatOptions = formatOpt
expOpt.ExportFormatType = crReportExportFormatPDF



Dim exportControl  ', rptFactory, rptSource
Set exportControl = Server.CreateObject("CrystalReports.CrystalReportExportControl")

   
    Dim HTMLViewer
    Set HTMLViewer = ObjectFactory.CreateObject("CrystalReports.CrystalReportViewer")
       
    if (Not (IsEmpty(serializedRptSrc) OR (Len(serializedRptSrc) = 0))) then
        ' Got a seralizedRprtSrc string
        ' need to deserialize the report source string and pass to viewer
        Dim XMLSerializer
        Set XMLSerializer = ObjectFactory.CreateObject("CrystalReports.SAXXMLSerializer")
       
        XMLSerializer.SetObjectCreator ObjectFactory    
        HTMLViewer.ReportSource = XMLSerializer.CreateObjectFromString(serializedRptSrc)
       
        set Session.Contents(reportid) = HTMLViewer.ReportSource
    else

    end if

'------EXPORT-----
With exportControl
      '.EnterpriseLogon = iStore.EnterpriseSession
      .ReportSource = Session.Contents(reportid)
      .Name = "PreviewPDF"
      .IsOwnForm = true
      .IsOwnPage = true
      .ExportOptions = expOpt
      .ExportAsAttachment = false
End With

 
  exportControl.ProcessHttpRequest Request, Response, Session

'-------

    if Err.number <> 0 then
        Response.Write Err.Description
        Err.Clear
    end if          

end if

%>
------------------------------------------------------------------------
0
mlmccCommented:
Is the report saved with data?

mlmcc
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Stella PauleyAuthor Commented:
no.. but the report is running in the developer.. XI has the same preview as previous version.. (lightning bolt icon is now a print preview icon)..
but it also has an HTML preview button that uses IE as a plugin (opens in the developer not in a new browser window)...

This function requires the Crystal XI Server..
0
Stella PauleyAuthor Commented:
Well.. I gave up tring to figure it out.. and was just going to use it by hitting HTMLPreview then Hitting Refresh...
I decided to go ahead and test it with the new Adobe Reader v7.. and guess what...
It works when you hit HTMLPreview... You don't have to hit refresh...
It must have been some sort of bug in Adobe Reader v6 that I was running into...

Anyway... got it all working... Cleaned up my code a bit... Here is my final file....

-----------------
<%@ Language=VBScript codepage=65001%>

<% Option Explicit
   On Error Resume Next

Response.ExpiresAbsolute = Now() - 1
const CLOSED_RPT_ID = "closedreportid"
const RPT_ID = "reportid"
const RPT_SOURCE = "reportsource"

Dim requestMethod
requestMethod = UCase(Request.ServerVariables("REQUEST_METHOD"))

Dim serializedRptSrc, reportid, closedreportid
if (requestMethod = "POST") then
    serializedRptSrc = Request.Form(RPT_SOURCE)
    closedreportid = Request.Form(CLOSED_RPT_ID)
else
    serializedRptSrc = Request.QueryString(RPT_SOURCE)
    closedreportid = Request.QueryString(CLOSED_RPT_ID)
end if

' reportid is always passed in the URL
reportid = Request.QueryString(RPT_ID)

if (Not (IsEmpty(closedreportid) OR (Len(closedreportid) = 0))) then
    ' Clear the report source in session with the given closedreportid
    Session.Contents.Remove(closedreportid)
end if

if (Not (IsEmpty(reportid) OR (Len(reportid) = 0))) then
 
    Dim objectFactory
    ' Use the version dependent prog id for side by side support
    ' (i.e. to maintain consistency when multiple versions of the product is installed)
    Set objectFactory = CreateObject("CrystalReports11.ObjectFactory.1")

Dim expOpt, formatOpt
Set expOpt = ObjectFactory.CreateObject("CrystalReports.ExportOptions")
Set formatOpt = ObjectFactory.CreateObject("CrystalReports.PDFExportFormatOptions")

Dim crReportExportFormatPDF
crReportExportFormatPDF = 5

expOpt.FormatOptions = formatOpt
expOpt.ExportFormatType = crReportExportFormatPDF

Dim exportControl  
Set exportControl = Server.CreateObject("CrystalReports.CrystalReportExportControl")
       
    if (Not (IsEmpty(serializedRptSrc) OR (Len(serializedRptSrc) = 0))) then
        ' Got a seralizedRprtSrc string
        ' need to deserialize the report source string and pass to viewer
        Dim XMLSerializer
        Set XMLSerializer = ObjectFactory.CreateObject("CrystalReports.SAXXMLSerializer")
            XMLSerializer.SetObjectCreator ObjectFactory    

    set Session.Contents(reportid) = XMLSerializer.CreateObjectFromString(serializedRptSrc)
    end if

With exportControl
      .ReportSource = Session.Contents(reportid)
      .Name = "PreviewPDF"
      .IsOwnForm = true
      .IsOwnPage = true
      .ExportOptions = expOpt
      .ExportAsAttachment = true
End With


'----RUN THE REPORT----
  exportControl.ProcessHttpRequest Request, Response, Session

'-------

    if Err.number <> 0 then
        Response.Write Err.Description
        Err.Clear
    end if          

end if

%>

------------------
0
mlmccCommented:
Glad i could help

mlmcc
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.