Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Opening the PDF file at client side.

Posted on 2011-02-20
2
Medium Priority
?
601 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
2 Comments
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 2000 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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

971 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