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

corrupted file

2 Answers 482 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 14 Jun 2013, 09:44 PM
When i run the following code a pdf is created but it will not open.  When i try to open it manually by double clicking on it an error which says that adobe can not open the file because it has been corrupted somehow . . . . . . .
The commented out lines are things that I have tried.
Telerik.Reporting.Report Telrpt = new TelRptContract();
                    Telerik.Reporting.Processing.ReportProcessor TelContractrp = new Telerik.Reporting.Processing.ReportProcessor();
                    System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                    Telerik.Reporting.InstanceReportSource TelContractirs = new Telerik.Reporting.InstanceReportSource();
                    TelContractirs.ReportDocument = Telrpt;
                    Telerik.Reporting.Processing.RenderingResult result = TelContractrp.RenderReport("PDF", TelContractirs, deviceInfo);
                    string fileName2 = result.DocumentName + "." + result.Extension;
                    //string path2 = "c:\\Users\\akinw\\Desktop\\";
                    //string path2 = System.IO.Path.GetTempPath();
                    string path2 = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                    string filePath2 = System.IO.Path.Combine(path2, fileName2);
                    FileStream fs = new FileStream(filePath2, FileMode.Create);       
                    fs.Close();
                    //fs = File.Open(filePath2, FileMode.Open);
                    System.IO.File.Open(filePath2, FileMode.Open);

2 Answers, 1 is accepted

Sort by
0
Squall
Top achievements
Rank 1
answered on 17 Jun 2013, 11:10 AM
You have to write the document bytes with the filestream:

Telerik.Reporting.Processing.ReportProcessor reportProcessor =
    new Telerik.Reporting.Processing.ReportProcessor();
 
//set any deviceInfo settings if necessary
System.Collections.Hashtable deviceInfo =
    new System.Collections.Hashtable();
 
Telerik.Reporting.InstanceReportSource instanceReportSource =
    new Telerik.Reporting.InstanceReportSource();
 
instanceReportSource.ReportDocument = report1;
 
Telerik.Reporting.Processing.RenderingResult result =
    reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
 
string fileName = result.DocumentName + "." + result.Extension;
string path = System.IO.Path.GetTempPath();
string filePath = System.IO.Path.Combine(path, fileName);
 
using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
{
    fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
}
0
William
Top achievements
Rank 1
answered on 17 Jun 2013, 01:50 PM
That did the trick thanks.
Tags
General Discussions
Asked by
William
Top achievements
Rank 1
Answers by
Squall
Top achievements
Rank 1
William
Top achievements
Rank 1
Share this question
or