I need to generate and save a report to disk from a standard Windows
 Application without user intervention.
 So basically, a user clicks a button, and a report is saved to his c:\ in a
 predefined format and with a predefined filename.
 Anyone?
 J. Jespersen> So basically, a user clicks a button, and a report is saved to his c:\ in
> a
> predefined format and with a predefined filename.
Correction: File should just be saved to the servers c:\|||This code will allow you to generate a report, and create a PDF file from it.
You can tweak the parameters to export the format and type you wish:
 public static void deliverReport()
 {
 MyReportingService.ReportingService rs = new ReportingService();
 rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
 // Render arguments
 byte[] rpt = null;
 string reportPath = "/ReportProject1/Report1";
 string format = "PDF";
 string historyID = null;
 string devInfo =@."<DeviceInfo><StartPage>0</StartPage><PageHeight>8.5in</PageHeight><PageWidth>14in</PageWidth></DeviceInfo>";
 ParameterValue[] parameters = new ParameterValue[0];
 DataSourceCredentials[] credentials = null;
 string showHideToggle = null;
 string encoding;
 string mimeType;
 Warning[] warnings = null;
 ParameterValue[] reportHistoryParameters = null;
 string[] streamIDs = null;
 SessionHeader sh = new SessionHeader();
 rs.SessionHeaderValue = sh;
 rpt = rs.Render(reportPath, format, historyID, devInfo,
parameters, credentials,
 showHideToggle, out encoding, out mimeType, out
reportHistoryParameters, out warnings,
 out streamIDs);
 FileStream stream = File.Create("test.pdf", rpt.Length);
 stream.Write(rpt, 0, rpt.Length);
 stream.Close();
 }
This URL may help you as well:
http://www.csharphelp.com/archives3/archive545.html
Cheers,
 Rich
"Jeppe Dige Jespersen" wrote:
> > So basically, a user clicks a button, and a report is saved to his c:\ in
> > a
> > predefined format and with a predefined filename.
> Correction: File should just be saved to the servers c:\
>
>|||Thank you Rich. Works perfectly! :-)
Jeppe Jespersen
Denmark
> This code will allow you to generate a report, and create a PDF file from
> it.
> You can tweak the parameters to export the format and type you wish:
> public static void deliverReport()
> {
> MyReportingService.ReportingService rs = new
> ReportingService();
> rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
> // Render arguments
> byte[] rpt = null;
> string reportPath = "/ReportProject1/Report1";
> string format = "PDF";
> string historyID = null;
> string devInfo => @."<DeviceInfo><StartPage>0</StartPage><PageHeight>8.5in</PageHeight><PageWidth>14in</PageWidth></DeviceInfo>";
> ParameterValue[] parameters = new ParameterValue[0];
> DataSourceCredentials[] credentials = null;
> string showHideToggle = null;
> string encoding;
> string mimeType;
> Warning[] warnings = null;
> ParameterValue[] reportHistoryParameters = null;
> string[] streamIDs = null;
> SessionHeader sh = new SessionHeader();
> rs.SessionHeaderValue = sh;
> rpt = rs.Render(reportPath, format, historyID, devInfo,
> parameters, credentials,
> showHideToggle, out encoding, out mimeType, out
> reportHistoryParameters, out warnings,
> out streamIDs);
> FileStream stream = File.Create("test.pdf", rpt.Length);
> stream.Write(rpt, 0, rpt.Length);
> stream.Close();
> }
> This URL may help you as well:
> http://www.csharphelp.com/archives3/archive545.html
> Cheers,
> Rich
> "Jeppe Dige Jespersen" wrote:
>> > So basically, a user clicks a button, and a report is saved to his c:\
>> > in
>> > a
>> > predefined format and with a predefined filename.
>> Correction: File should just be saved to the servers c:\
>>
 
No comments:
Post a Comment