This is a migrated thread and some comments may be shown as answers.

Error after exporting to PDF

1 Answer 183 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
haitham
Top achievements
Rank 1
haitham asked on 26 Nov 2015, 05:51 PM

Hi,

I create a report and i try to export it to PDF, I'm using C# ASP.net MVC 4 , but an unknown error occured and I can't resolve it, can you help me please, 

this is the C# Source code
and I the print screen of the generated PDF file in the attachements

 

        public ActionResult PrintRpt(int myId)
        {
            try
            {
                myReport report = new myReport();
                report.sqlDataSourceMyReport.Parameters[0].Value = myId;
                report.sqlDataSourceMyReport.ConnectionString = "";
                var processor = new ReportProcessor();
                var res = processor.RenderReport("PDF", report, null);
                var pdfSteream = new MemoryStream(res.DocumentBytes);
                FileStream file = new FileStream("d:\\file.pdf", FileMode.Create, FileAccess.Write);
                pdfSteream.WriteTo(file);
                file.Close();
                pdfSteream.Close();
                byte[] bytes = pdfSteream.ToArray();
                string base64String = string.Empty;
                try
                {
                    base64String = System.Convert.ToBase64String(bytes, 0, bytes.Length);
                    byte[] binaryData = System.Convert.FromBase64String(base64String);
                }
                catch (System.ArgumentNullException)
                {
                    throw new Exception("Binary data array is null.");
                }
                return Json(base64String, JsonRequestBehavior.AllowGet);
            }
            catch (Exception e)
            {
                return Json(e, JsonRequestBehavior.AllowGet);
            }
        }

 

 

1 Answer, 1 is accepted

Sort by
0
haitham
Top achievements
Rank 1
answered on 26 Nov 2015, 05:53 PM

I had an error on the connection string :p

 

Tags
General Discussions
Asked by
haitham
Top achievements
Rank 1
Answers by
haitham
Top achievements
Rank 1
Share this question
or