Solved

Opening the PDF file at client side.

Posted on 2011-02-20
2
598 Views
Last Modified: 2012-05-11
Hi,
I am working on a web application. I have to generate a report in PDF at client side.
Below is my code. It is trying to create the report in server. But it has to create the PDF file at client side.

Can anyone suggest me what changes I need to make to this code.
protected void lnkPdf_Click(object sender, EventArgs e)
        {
            byte[] result = null;
            result = GetReport("AssetTolReport.rpt", CEReportFormat.PDF);//DataTest
            string currentDir = "";
            string tmpReportName = "AssetTolerance" + DateTime.Now.Ticks.ToString() + ".PDF";
            FileStream fs = new FileStream(Path.Combine(currentDir, tmpReportName), FileMode.Create, FileAccess.Write);
            fs.Write(result, 0, result.Length);
            fs.Close();
            Process.Start(fs.Name);
        }

        /// <summary>
        /// To convert the crystal report to PDF
        /// </summary>
        /// <param name="reportName"></param>
        /// <param name="reportFormat"></param>
        /// <returns><see cref="result"/></returns>
        public byte[] GetReport(string reportName, CEReportFormat reportFormat) 
        {
            SessionInfo sessionInfo = Utility.GetSessionInfo();
            byte[] result = null;
            string acctId = txtAccount.Text;
            DataSet ds = new DataSet();
            ds = WebUIController.GetAssetToleranceDataSet(acctId);
            ds.Tables[0].TableName = "GPQ_ACCT";               
            result = ReportHelper.ExecuteReport(sessionInfo,reportName, reportFormat, ds);
            return r

Open in new window

0
Comment
Question by:GouthamAnand
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 500 total points
ID: 34939252
Just to be clear you definitely have to *create* the PDF document on the server, but I am assuming you want to deliver it to the client? Also not sure what Process.Start() does?

In which case you do the following:

String FileName = "YourFileName.pdf";
byte[] FileData = ; // Your File Data

Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + FileName);
Response.BinaryWrite(FileData);
Response.End();
0
 

Author Closing Comment

by:GouthamAnand
ID: 34939454
Thanks a lot
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question