|
using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Web.Services.Protocols;
using Rse2005 = ReportExecution2005;
public partial class RsPdf : System.Web.UI.Page
{
private string RptMemo="";
protected void Page_Load(object sender, EventArgs e)
{
}
//
protected void BtnSubmit_Click(object sender, EventArgs e)
{
//we only care about first 50 characters
string tmpStr = txtRptMemo.Text.Trim();
if(""==tmpStr)
{
tmpStr = "Your input from web browser";
}
else if (tmpStr.Length > 50)
{
tmpStr = tmpStr.Substring(0, 50);
}
else
{
//do nothing
}
RptMemo = tmpStr;
RenderPdf();
}
//Call Reporting service to render PDF
private void RenderPdf()
{
// Prepare Render arguments
string historyID = null;
string deviceInfo = null;
string format = "PDF";
Byte[] results;
string encoding = String.Empty;
string mimeType = String.Empty;
string extension = String.Empty;
Rse2005.Warning[] warnings = null;
string[] streamIDs = null;
Rse2005.ReportExecutionService rsExec = new Rse2005.ReportExecutionService();
rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
//rsExec.Credentials = new NetworkCredential(username, password, domain);
Rse2005.ExecutionInfo ei = rsExec.LoadReport("/PdfReport/pdf01", historyID);
Rse2005.ParameterValue[] rptParameters = new Rse2005.ParameterValue[1];
rptParameters[0] = new Rse2005.ParameterValue();
rptParameters[0].Name = "ReportMemo";
rptParameters[0].Value = RptMemo;
//render the PDF
rsExec.SetExecutionParameters(rptParameters, "en-us");
results = rsExec.Render(format, deviceInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
Response.AddHeader("content-disposition", "attachment; filename=pdf01.pdf");
Response.OutputStream.Write(results, 0, results.Length);
//This is very important if you want to directly download from stream instead of file
Response.End();
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.