[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

To save dynamically generated pdf to web server automatically without prompting user

Posted on 2012-04-10
4
Medium Priority
?
433 Views
Last Modified: 2012-04-20
Hi Experts,

I am generating rdlc report in asp.net (visual studio 2010). Currently, using the following code, I am able to export the report to pdf format on a button click event. Response.Flush()  in the end is prompting user to download it at the desired location.

What I want is,
1) Instead of generating a pdf on a button click, I want to export my report automatically  to pdf after the report gets generated on a page load event
2) That pdf report should get saved automatically at the specified location on the web server instead of prompting user to download it on their PC.

Is this achievable?



 protected void CreatePDF()
        {
           
            // Variables
            Warning[] warnings;
            string[] streamIds;
            string mimeType = string.Empty;
            string encoding = string.Empty;
            string extension = string.Empty;
            string fileName="Quote"+hdnRegistrationNo.Value+".pdf";
            string savelocation = Server.MapPath("Registrations")+ "\\" + fileName;
           
            // Setup the report viewer object and get the array of bytes
         
            byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out     encoding, out extension, out streamIds, out warnings);

            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = mimeType;
            Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
            Response.Flush();
           
        }
0
Comment
Question by:Tina_Bhole
[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
  • 3
4 Comments
 
LVL 42

Accepted Solution

by:
Meir Rivkin earned 750 total points
ID: 37831256
after calling LocalReport.Render, use the following code to save it on the server:

-> fileName: the pdf file path on the server

using (FileStream stream = File.OpenWrite(fileName))
  {
    stream.Write(bytes , 0, bytes.Length);
  }

Open in new window

0
 

Author Comment

by:Tina_Bhole
ID: 37835943
Thanks for your reply sedgwick. Is there any way to eliminate clicking of the button to call CreatePDF() function. Can it be called automatically after the report loads?
0
 

Assisted Solution

by:Tina_Bhole
Tina_Bhole earned 0 total points
ID: 37849435
I managed to achieve what I wanted by calling CreatePDF() in Form_Load event as follows:


 if (IsPostBack)
            {
                CreatePDF();
            }


After the report loads it calls postback event and then the pdf gets generated automatically.
0
 

Author Closing Comment

by:Tina_Bhole
ID: 37869827
Sedwick answered one out of 2 questions I asked. I found answer to the second question on my own.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 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